Removed NDEBUG-dependent SimTK::StateImpl members #738
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Although the members that are affected by this diff (
m_qVersion
,m_discreteVarVersions
, etc.) are unused in release builds, it is dangerous to conditionally expose them.The reason why is because of ABI breakages.
StateImpl.h
is a header that can, in principle, be included by downstream code (I know it'sinternal/
, but that won't stop it from being transitively included by, e.g. OpenSim) there is a chance that different compilation units will compile different downstream code based on what theirNDEBUG
is set to (might be different from simbody's build).I have read in other PRs, issues, etc. on both
simbody
andopensim-core
that downstream projects must be compiled with the same optimization+debug levels. This should not be the case. It is perfectly normal to use a downstream debug binary with an upstream release library (think about graphics bindings, OS APIs, game engines, etc.).The only exception is maybe MSVC, which has some kind of iterator debug level macro in its standard library, which causes is to cry quite a bit if you mix up flags. I have only seen this in MSVC--specifically for iterators--and both OSX and Linux are usually ok with mixing debug levels.
This patch makes
StateImpl
slightly bigger but, assuming empty containers cause no allocations, the overhead should be small compared to the rest of the datastructure. If there is genuinely a performance concern then I would recommend heap-allocating aDebugData
struct behind aunique_ptr
to put a cap (pointer size) on the overhead.This change is