From 629222346acd8883b06f411dd85ff412496f3dfc Mon Sep 17 00:00:00 2001
From: Florian Schmaus <flow@cs.fau.de>
Date: Tue, 10 Nov 2020 15:09:58 +0100
Subject: [PATCH] Fix debug-build specific #include statements

---
 emper/Context.hpp |  5 ++++-
 emper/Debug.hpp   |  9 ++++-----
 emper/Fiber.cpp   |  3 +++
 emper/Fiber.hpp   |  5 ++++-
 emper/Runtime.cpp | 10 +++++++---
 5 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/emper/Context.hpp b/emper/Context.hpp
index 7fa56a37..8f996c53 100644
--- a/emper/Context.hpp
+++ b/emper/Context.hpp
@@ -4,7 +4,6 @@
 
 #include <cassert>			// for assert
 #include <cstdint>			// for uintptr_t
-#include <cstring>			// for memset
 #include <functional>		// for function
 #include <iosfwd>				// for ostream
 #include <type_traits>	// for remove_reference<>::type
@@ -13,6 +12,10 @@
 #include "Common.hpp"	 // for func_t, DIE, ALIGN_TO_CACHE_LINE
 #include "Debug.hpp"	 // for LOGD, LogSubsystem, LogSubsystem::C, Logger
 
+#ifndef NDEBUG
+#include <cstring>	// for memset
+#endif
+
 extern "C" [[noreturn]] void switch_and_load_context(void** toTos);
 // *Not* marked as 'noreturn' because save_and_switch_context does
 // *actually return at some point, unlike the other switch_*
diff --git a/emper/Debug.hpp b/emper/Debug.hpp
index dbf47c1c..a4d99c28 100644
--- a/emper/Debug.hpp
+++ b/emper/Debug.hpp
@@ -2,8 +2,10 @@
 // Copyright © 2020 Florian Schmaus
 #pragma once
 
-#include <map>		 // for allocator, map
-#include <string>	 // for string, operator<<
+#include <iostream>	 // IWYU pragma: keep
+#include <map>			 // for allocator, map
+#include <sstream>	 // IWYU pragma: keep
+#include <string>		 // for string, operator<<
 
 #ifdef NDEBUG
 
@@ -14,9 +16,6 @@
 
 #else
 
-#include <iostream>	 // IWYU pragma: keep
-#include <sstream>	 // IWYU pragma: keep
-
 // If we apply clang-format to the following region, then clang-format
 // will create multi-line macros. However clang-tidy's NOLINTNEXTLINE
 // would then not work. :(
diff --git a/emper/Fiber.cpp b/emper/Fiber.cpp
index 61423875..0c8eb418 100644
--- a/emper/Fiber.cpp
+++ b/emper/Fiber.cpp
@@ -3,7 +3,10 @@
 #include "Fiber.hpp"
 
 #include <iostream>	 // for operator<<, basic_ostream, ostream, basic_ostrea...
+
+#ifndef NDEBUG
 #include <typeinfo>	 // for type_info
+#endif
 
 void Fiber::run() const {
 	LOGD("run() calling " << function.target<FIBER_FUN_TEMPLATE_ARG>() << " ("
diff --git a/emper/Fiber.hpp b/emper/Fiber.hpp
index 2e95c8a8..4723eaf5 100644
--- a/emper/Fiber.hpp
+++ b/emper/Fiber.hpp
@@ -4,7 +4,6 @@
 
 #include <atomic>				// for atomic_uint, atomic, __atomic_base, memory...
 #include <cassert>			// for assert
-#include <climits>			// for UINT_MAX
 #include <functional>		// for function
 #include <iosfwd>				// for ostream
 #include <new>					// for operator new
@@ -15,6 +14,10 @@
 #include "Debug.hpp"			 // for LogSubsystem, LogSubsystem::F, Logger
 #include "emper-common.h"	 // for workeraffinity_t, UNUSED_ARG
 
+#ifndef NDEBUG
+#include <climits>	// for UINT_MAX
+#endif
+
 namespace adt {
 template <typename T>
 class MpscQueue;
diff --git a/emper/Runtime.cpp b/emper/Runtime.cpp
index 47157ff4..b413c742 100644
--- a/emper/Runtime.cpp
+++ b/emper/Runtime.cpp
@@ -8,12 +8,9 @@
 // Non portable.
 #include <sched.h>				// for cpu_set_t, CPU_SET, CPU_ZERO
 #include <sys/sysinfo.h>	// for get_nprocs
-#include <syscall.h>			// for SYS_gettid
-#include <unistd.h>				// for syscall
 
 #include <cstdlib>	// for rand, srand, abort
 #include <memory>		// for __shared_ptr_access, shared_ptr
-#include <ostream>	// for operator<<, basic_ostream<>:...
 
 #include "Common.hpp"										 // for DIE_MSG_ERRNO, DIE, DIE_MSG
 #include "ContextManager.hpp"						 // for ContextManager
@@ -24,6 +21,13 @@
 #include "RuntimeStrategyStats.hpp"			 // for RuntimeStrategyStats
 #include "strategies/ws/WsStrategy.hpp"	 // for WsStrategy, WsStrategy::INST...
 
+#ifndef NDEBUG
+#include <syscall.h>	// for SYS_gettid
+#include <unistd.h>		// for syscall
+
+#include <ostream>	// for operator<<, basic_ostream<>:...
+#endif
+
 std::mutex Runtime::currentRuntimeMutex;
 Runtime* Runtime::currentRuntime;
 thread_local unsigned int Runtime::seed;
-- 
GitLab