Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/internal
diff options
context:
space:
mode:
authorMartin Hořeňovský2020-05-10 10:20:48 +0200
committerMartin Hořeňovský2020-05-10 15:37:29 +0200
commit7efbc83ae0393500692851525b89cfa890f3cee0 (patch)
treeb00e6d57b2753d675fc9201a341c49cb6788cfaf /src/catch2/internal
parent9e498278be92ff209687a09b989f27d51aab7809 (diff)
downloadcatch3-7efbc83ae0393500692851525b89cfa890f3cee0.tar.gz
Introduce combined TUs for compiling small TUs
This should improve the compilation times by decreasing the number of TUs compiled, without making overly big TUs that would cause problems with heavy-tailed compilation times. There is one "combined TU" for the top level part, and each subpart, except for Reporters, which currently do not have any trivial TUs.
Diffstat (limited to 'src/catch2/internal')
-rw-r--r--src/catch2/internal/catch_combined_tu.cpp173
-rw-r--r--src/catch2/internal/catch_decomposer.cpp24
-rw-r--r--src/catch2/internal/catch_errno_guard.cpp15
-rw-r--r--src/catch2/internal/catch_leak_detector.cpp37
-rw-r--r--src/catch2/internal/catch_polyfills.cpp31
-rw-r--r--src/catch2/internal/catch_startup_exception_registry.cpp26
-rw-r--r--src/catch2/internal/catch_uncaught_exceptions.cpp21
7 files changed, 173 insertions, 154 deletions
diff --git a/src/catch2/internal/catch_combined_tu.cpp b/src/catch2/internal/catch_combined_tu.cpp
new file mode 100644
index 00000000..c6819362
--- /dev/null
+++ b/src/catch2/internal/catch_combined_tu.cpp
@@ -0,0 +1,173 @@
+/** \file
+ * This is a special TU that combines what would otherwise be a very
+ * small top-level TUs into one bigger TU.
+ *
+ * The reason for this is compilation performance improvements by
+ * avoiding reparsing headers for many small TUs, instead having this
+ * one TU include bit more, but having it all parsed only once.
+ *
+ * To avoid heavy-tail problem with compilation times, each "subpart"
+ * of Catch2 has its own combined TU like this.
+ */
+
+
+////////////////////////////////////////////////////////
+// vvv formerly catch_tag_alias_autoregistrar.cpp vvv //
+////////////////////////////////////////////////////////
+
+#include <catch2/catch_tag_alias_autoregistrar.hpp>
+#include <catch2/internal/catch_compiler_capabilities.hpp>
+#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
+
+namespace Catch {
+
+ RegistrarForTagAliases::RegistrarForTagAliases(char const* alias, char const* tag, SourceLineInfo const& lineInfo) {
+ CATCH_TRY {
+ getMutableRegistryHub().registerTagAlias(alias, tag, lineInfo);
+ } CATCH_CATCH_ALL {
+ // Do not throw when constructing global objects, instead register the exception to be processed later
+ getMutableRegistryHub().registerStartupException();
+ }
+ }
+
+}
+
+
+//////////////////////////////////////////
+// vvv formerly catch_polyfills.cpp vvv //
+//////////////////////////////////////////
+
+#include <catch2/internal/catch_polyfills.hpp>
+#include <catch2/internal/catch_compiler_capabilities.hpp>
+#include <cmath>
+
+namespace Catch {
+
+#if !defined(CATCH_CONFIG_POLYFILL_ISNAN)
+ bool isnan(float f) {
+ return std::isnan(f);
+ }
+ bool isnan(double d) {
+ return std::isnan(d);
+ }
+#else
+ // For now we only use this for embarcadero
+ bool isnan(float f) {
+ return std::_isnan(f);
+ }
+ bool isnan(double d) {
+ return std::_isnan(d);
+ }
+#endif
+
+} // end namespace Catch
+
+
+////////////////////////////////////////////////////
+// vvv formerly catch_uncaught_exceptions.cpp vvv //
+////////////////////////////////////////////////////
+
+#include <catch2/internal/catch_compiler_capabilities.hpp>
+#include <catch2/internal/catch_uncaught_exceptions.hpp>
+#include <exception>
+
+namespace Catch {
+ bool uncaught_exceptions() {
+#if defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) || (defined(__cpp_lib_uncaught_exceptions) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS))
+ return std::uncaught_exceptions() > 0;
+#else
+ return std::uncaught_exception();
+#endif
+ }
+} // end namespace Catch
+
+
+////////////////////////////////////////////
+// vvv formerly catch_errno_guard.cpp vvv //
+////////////////////////////////////////////
+#include <catch2/internal/catch_errno_guard.hpp>
+
+#include <cerrno>
+
+namespace Catch {
+ ErrnoGuard::ErrnoGuard():m_oldErrno(errno){}
+ ErrnoGuard::~ErrnoGuard() { errno = m_oldErrno; }
+}
+
+
+///////////////////////////////////////////
+// vvv formerly catch_decomposer.cpp vvv //
+///////////////////////////////////////////
+#include <catch2/internal/catch_decomposer.hpp>
+
+namespace Catch {
+
+ ITransientExpression::~ITransientExpression() = default;
+
+ void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ) {
+ if( lhs.size() + rhs.size() < 40 &&
+ lhs.find('\n') == std::string::npos &&
+ rhs.find('\n') == std::string::npos )
+ os << lhs << ' ' << op << ' ' << rhs;
+ else
+ os << lhs << '\n' << op << '\n' << rhs;
+ }
+}
+
+
+///////////////////////////////////////////////////////////
+// vvv formerly catch_startup_exception_registry.cpp vvv //
+///////////////////////////////////////////////////////////
+#include <catch2/internal/catch_startup_exception_registry.hpp>
+#include <catch2/internal/catch_compiler_capabilities.hpp>
+
+namespace Catch {
+void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept {
+ CATCH_TRY {
+ m_exceptions.push_back(exception);
+ } CATCH_CATCH_ALL {
+ // If we run out of memory during start-up there's really not a lot more we can do about it
+ std::terminate();
+ }
+ }
+
+ std::vector<std::exception_ptr> const& StartupExceptionRegistry::getExceptions() const noexcept {
+ return m_exceptions;
+ }
+
+} // end namespace Catch
+
+
+//////////////////////////////////////////////
+// vvv formerly catch_leak_detector.cpp vvv //
+//////////////////////////////////////////////
+ #include <catch2/internal/catch_leak_detector.hpp>
+ #include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
+
+
+#ifdef CATCH_CONFIG_WINDOWS_CRTDBG
+#include <crtdbg.h>
+
+namespace Catch {
+
+ LeakDetector::LeakDetector() {
+ int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
+ flag |= _CRTDBG_LEAK_CHECK_DF;
+ flag |= _CRTDBG_ALLOC_MEM_DF;
+ _CrtSetDbgFlag(flag);
+ _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
+ _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
+ // Change this to leaking allocation's number to break there
+ _CrtSetBreakAlloc(-1);
+ }
+}
+
+#else // ^^ Windows crt debug heap enabled // Windows crt debug heap disabled vv
+
+ Catch::LeakDetector::LeakDetector() {}
+
+#endif // CATCH_CONFIG_WINDOWS_CRTDBG
+
+Catch::LeakDetector::~LeakDetector() {
+ Catch::cleanUp();
+}
diff --git a/src/catch2/internal/catch_decomposer.cpp b/src/catch2/internal/catch_decomposer.cpp
deleted file mode 100644
index e1018cd6..00000000
--- a/src/catch2/internal/catch_decomposer.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Created by Phil Nash on 8/8/2017.
- * Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
- *
- * Distributed under the Boost Software License, Version 1.0. (See accompanying
- * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- */
-
-#include <catch2/internal/catch_decomposer.hpp>
-#include <catch2/catch_config.hpp>
-
-namespace Catch {
-
- ITransientExpression::~ITransientExpression() = default;
-
- void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ) {
- if( lhs.size() + rhs.size() < 40 &&
- lhs.find('\n') == std::string::npos &&
- rhs.find('\n') == std::string::npos )
- os << lhs << ' ' << op << ' ' << rhs;
- else
- os << lhs << '\n' << op << '\n' << rhs;
- }
-}
diff --git a/src/catch2/internal/catch_errno_guard.cpp b/src/catch2/internal/catch_errno_guard.cpp
deleted file mode 100644
index 3cc3697c..00000000
--- a/src/catch2/internal/catch_errno_guard.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Created by Martin on 06/03/2017.
- *
- * Distributed under the Boost Software License, Version 1.0. (See accompanying
- * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- */
-
-#include <catch2/internal/catch_errno_guard.hpp>
-
-#include <cerrno>
-
-namespace Catch {
- ErrnoGuard::ErrnoGuard():m_oldErrno(errno){}
- ErrnoGuard::~ErrnoGuard() { errno = m_oldErrno; }
-}
diff --git a/src/catch2/internal/catch_leak_detector.cpp b/src/catch2/internal/catch_leak_detector.cpp
deleted file mode 100644
index 0f3ad29d..00000000
--- a/src/catch2/internal/catch_leak_detector.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Created by Martin on 12/07/2017.
- *
- * Distributed under the Boost Software License, Version 1.0. (See accompanying
- * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- */
-
- #include <catch2/internal/catch_leak_detector.hpp>
- #include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
-
-
-#ifdef CATCH_CONFIG_WINDOWS_CRTDBG
-#include <crtdbg.h>
-
-namespace Catch {
-
- LeakDetector::LeakDetector() {
- int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
- flag |= _CRTDBG_LEAK_CHECK_DF;
- flag |= _CRTDBG_ALLOC_MEM_DF;
- _CrtSetDbgFlag(flag);
- _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
- _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
- // Change this to leaking allocation's number to break there
- _CrtSetBreakAlloc(-1);
- }
-}
-
-#else
-
- Catch::LeakDetector::LeakDetector() {}
-
-#endif
-
-Catch::LeakDetector::~LeakDetector() {
- Catch::cleanUp();
-}
diff --git a/src/catch2/internal/catch_polyfills.cpp b/src/catch2/internal/catch_polyfills.cpp
deleted file mode 100644
index a4d54ea8..00000000
--- a/src/catch2/internal/catch_polyfills.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Created by Martin on 17/11/2017.
- *
- * Distributed under the Boost Software License, Version 1.0. (See accompanying
- * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- */
-
-#include <catch2/internal/catch_polyfills.hpp>
-
-#include <cmath>
-
-namespace Catch {
-
-#if !defined(CATCH_CONFIG_POLYFILL_ISNAN)
- bool isnan(float f) {
- return std::isnan(f);
- }
- bool isnan(double d) {
- return std::isnan(d);
- }
-#else
- // For now we only use this for embarcadero
- bool isnan(float f) {
- return std::_isnan(f);
- }
- bool isnan(double d) {
- return std::_isnan(d);
- }
-#endif
-
-} // end namespace Catch
diff --git a/src/catch2/internal/catch_startup_exception_registry.cpp b/src/catch2/internal/catch_startup_exception_registry.cpp
deleted file mode 100644
index 8fd7034b..00000000
--- a/src/catch2/internal/catch_startup_exception_registry.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Created by Martin on 04/06/2017.
- * Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
- *
- * Distributed under the Boost Software License, Version 1.0. (See accompanying
- * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- */
-
-#include <catch2/internal/catch_startup_exception_registry.hpp>
-#include <catch2/internal/catch_compiler_capabilities.hpp>
-
-namespace Catch {
-void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept {
- CATCH_TRY {
- m_exceptions.push_back(exception);
- } CATCH_CATCH_ALL {
- // If we run out of memory during start-up there's really not a lot more we can do about it
- std::terminate();
- }
- }
-
- std::vector<std::exception_ptr> const& StartupExceptionRegistry::getExceptions() const noexcept {
- return m_exceptions;
- }
-
-} // end namespace Catch
diff --git a/src/catch2/internal/catch_uncaught_exceptions.cpp b/src/catch2/internal/catch_uncaught_exceptions.cpp
deleted file mode 100644
index 1aa863ad..00000000
--- a/src/catch2/internal/catch_uncaught_exceptions.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Created by Josh on 1/2/2018.
- * Copyright 2018 Two Blue Cubes Ltd. All rights reserved.
- *
- * Distributed under the Boost Software License, Version 1.0. (See accompanying
- * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- */
-
-#include <catch2/internal/catch_compiler_capabilities.hpp>
-#include <catch2/internal/catch_uncaught_exceptions.hpp>
-#include <exception>
-
-namespace Catch {
- bool uncaught_exceptions() {
-#if defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) || (defined(__cpp_lib_uncaught_exceptions) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS))
- return std::uncaught_exceptions() > 0;
-#else
- return std::uncaught_exception();
-#endif
- }
-} // end namespace Catch