Skip to content

Commit

Permalink
Merge bitcoin#28579: refactor: Remove redundant checks in compat/assu…
Browse files Browse the repository at this point in the history
…mptions.h

fa1a384 Move compat.h include from system.h to system.cpp (MarcoFalke)
8888753 Move compat/assumptions.h include to one place that actually needs it (MarcoFalke)
7777411 Remove __cplusplus from compat/assumptions.h (MarcoFalke)
faa3d4f Remove duplicate NDEBUG check from compat/assumptions.h (MarcoFalke)

Pull request description:

  Generally, compile-time checks should be close to the code that use them. Especially, since `compat/assumptions.h` is only included in one place, where iwyu suggests to remove it.

  Fix all issues:
  * The `NDEBUG` check is used in `util/check`, so it is redundant in `compat/assumptions.h`.
  * The `__cplusplus` check is redundant with `doc/dependencies.md` (see commit message).
  * Add missing `// IWYU pragma: keep` to avoid removing the include by accident.

ACKs for top commit:
  achow101:
    ACK fa1a384
  TheCharlatan:
    re-ACK fa1a384
  theuni:
    ACK fa1a384

Tree-SHA512: f8b6db84be5d8844a2267345c0b1405fcbc39b8b5eeaa24db5b8412a74145fe44cf188b6b0c39cc2b062690ed37ca5b4662473484afe28dbec6469e79961389b
  • Loading branch information
achow101 committed Nov 28, 2023
2 parents 75462b3 + fa1a384 commit 16b5b4b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/common/system.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2022 The Bitcoin Core developers
// Copyright (c) 2009-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand All @@ -12,6 +12,7 @@
#ifndef WIN32
#include <sys/stat.h>
#else
#include <compat/compat.h>
#include <codecvt>
#endif

Expand Down
8 changes: 2 additions & 6 deletions src/common/system.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2022 The Bitcoin Core developers
// Copyright (c) 2009-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand All @@ -10,11 +10,7 @@
#include <config/bitcoin-config.h>
#endif

#include <compat/assumptions.h>
#include <compat/compat.h>

#include <set>
#include <stdint.h>
#include <cstdint>
#include <string>

// Application startup time (used for uptime calculation)
Expand Down
14 changes: 0 additions & 14 deletions src/compat/assumptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,6 @@
#include <cstddef>
#include <limits>

// Assumption: We assume that the macro NDEBUG is not defined.
// Example(s): We use assert(...) extensively with the assumption of it never
// being a noop at runtime.
#if defined(NDEBUG)
# error "Bitcoin cannot be compiled without assertions."
#endif

// Assumption: We assume a C++17 (ISO/IEC 14882:2017) compiler (minimum requirement).
// Example(s): We assume the presence of C++17 features everywhere :-)
// ISO Standard C++17 [cpp.predefined]p1:
// "The name __cplusplus is defined to the value 201703L when compiling a C++
// translation unit."
static_assert(__cplusplus >= 201703L, "C++17 standard assumed");

// Assumption: We assume the floating-point types to fulfill the requirements of
// IEC 559 (IEEE 754) standard.
// Example(s): Floating-point division by zero in ConnectBlock, CreateTransaction
Expand Down
4 changes: 2 additions & 2 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include <hash.h>
#include <headerssync.h>
#include <index/blockfilterindex.h>
#include <kernel/chain.h>
#include <kernel/mempool_entry.h>
#include <logging.h>
#include <kernel/chain.h>
#include <merkleblock.h>
#include <netbase.h>
#include <netmessagemaker.h>
Expand All @@ -39,7 +39,7 @@
#include <txmempool.h>
#include <txorphanage.h>
#include <txrequest.h>
#include <util/check.h> // For NDEBUG compile time check
#include <util/check.h>
#include <util/strencodings.h>
#include <util/trace.h>
#include <validation.h>
Expand Down
7 changes: 3 additions & 4 deletions src/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
#define BITCOIN_SERIALIZE_H

#include <attributes.h>
#include <compat/assumptions.h> // IWYU pragma: keep
#include <compat/endian.h>
#include <prevector.h>
#include <span.h>

#include <algorithm>
#include <cstdint>
Expand All @@ -18,13 +21,9 @@
#include <memory>
#include <set>
#include <string>
#include <string.h>
#include <utility>
#include <vector>

#include <prevector.h>
#include <span.h>

/**
* The maximum size of a serialized object in bytes or number of elements
* (for eg vectors) when the size is encoded as CompactSize.
Expand Down
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include <txmempool.h>
#include <uint256.h>
#include <undo.h>
#include <util/check.h> // For NDEBUG compile time check
#include <util/check.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <util/hasher.h>
Expand Down

0 comments on commit 16b5b4b

Please sign in to comment.