Since commit 7cee85807c4db679003c6659d247a2fe74c2464a ("Add compile time verification of assumptions we're currently making implicitly/tacitly", PR #15391), this check is done in compat/assumptions.h:
https://github.com/bitcoin/bitcoin/blob/8237889e8d0fb7542669a9098516c96da91913f0/src/compat/assumptions.h#L13-L18
This header is included by util/system.h, which is in turn included by most .cpp files, including the ones this commit modifies (validation.cpp and net_processing.cpp).
Remove redundant NDEBUG preprocessor checks #17459
pull theStack wants to merge 1 commits into bitcoin:master from theStack:20191112-remove-redundant-ndebug-checks changing 2 files +0 −8-
theStack commented at 12:11 AM on November 13, 2019: member
-
7f3397b234
Remove redundant NDEBUG preprocessor checks
Since commit 7cee85807c4db679003c6659d247a2fe74c2464a ("Add compile time verification of assumptions we're currently making implicitly/tacitly"), this check is done in compat/assumptions.h which is included by util/system.h, which is in turn included by most .cpp files, including the ones this commit modifies. - theStack force-pushed on Nov 13, 2019
- DrahtBot added the label P2P on Nov 13, 2019
- DrahtBot added the label Validation on Nov 13, 2019
- MarcoFalke added the label Refactoring on Nov 13, 2019
-
practicalswift commented at 10:17 PM on November 13, 2019: contributor
I'm all for removing redundancies in the general case, but in this specific case the redundancy is intentional:
Note that the inclusion of
assumptions.hcould be removed accidentally fromnet_processing.cppandvalidation.cppwithout breaking the build.Thus we cannot assume that
assumptions.hwill always be included :)I think of it this way:
- Enforcement: The
NDEBUGchecks innet_processing.cppandvalidation.cppmake sure that we enforce this project wide (since at least one of those files likely will be part of all relevant future builds of the project where this should be enforced). - Documentation: The
NDEBUGcheck inassumptions.hserves as a documentation of an important assumption we make.
Does that make sense? :)
- Enforcement: The
-
theStack commented at 12:02 AM on November 14, 2019: member
@practicalswift: Thanks for clarifying! My strong assumption was that in any possible build, one of the dozens
.cppfiles which currently include thecompat/assumptions.hheader (which after all says "compile-time verification", implying more than merely documentation) would also do so in the future, triggering the error in caseNDEBUGis set. Also it seemed quite fishy to me that the check was even present in two.cppfiles, not just one. Looking deeper into it, that seems to have historic reasons: introduced originally by gmaxwell with commit 9b59e3bda8c137bff885db5b1f9150346e36e076, theNDEBUGcheck was only present inmain.cpp. Then later whenmain.cppwas split up intovalidation.cppandnet_processing.cppit got copied over into both files (commits e736772c56a883e2649cc8534dd7857a0718ec56, 76faa3cdfedbd3fc91be4ecfff77fc6dc18134fb by TheBlueMatt; part of PR #9260 with a very entertaining title/description :laughing: ).Still feels odd to have the exact same preprocessor construct and error string scattered aorund in three places in the same project, but I get your point.
-
laanwj commented at 11:46 AM on November 15, 2019: member
Tend toward NACK. This code can go when the run-time critical assumptions stop using assertions. Then it is fully safe to define NDEBUG. Until then, belts and suspenders. (@MarcoFalke is working on this)
-
MarcoFalke commented at 5:23 PM on November 15, 2019: member
Yeah, if the goal is to make sure the assert can never be disabled by accident, but also avoid these preprocessor checks, you could cherry-pick something like fa1564326499f69eeb5427262ff0f26070f86146, replace the
std::abort();withassert(false), and add the preprocessor check to./src/util/check.h(a single place). -
laanwj commented at 12:30 PM on November 18, 2019: member
Though, I'd say it's not much of a goal in itself. Wouldn't be surprised if the preprocessor is the least CPU intensive part of the C++ compilation process.
-
fanquake commented at 8:57 AM on January 4, 2020: member
Closing as something that we can potentially revisit in the future.
- fanquake closed this on Jan 4, 2020
- DrahtBot locked this on Feb 15, 2022