Skip to content

Commit a6bce7e

Browse files
committed
Move SWIFT_ASSERT_ONLY to Compiler.h
1 parent 4a4a6b2 commit a6bce7e

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

include/swift/Basic/Compiler.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,29 @@
103103
#define SWIFT_CRASH_BUG_REPORT_MESSAGE \
104104
"Please " SWIFT_BUG_REPORT_MESSAGE_BASE " and the crash backtrace."
105105

106+
// Conditionally exclude declarations or statements that are only needed for
107+
// assertions from release builds (NDEBUG) without cluttering the surrounding
108+
// code by #ifdefs.
109+
//
110+
// struct DoThings {
111+
// SWIFT_ASSERT_ONLY_DECL(unsigned verifyCount = 0);
112+
// DoThings() {
113+
// SWIFT_ASSERT_ONLY(verifyCount = getNumberOfThingsToDo());
114+
// }
115+
// void doThings() {
116+
// do {
117+
// // ... do each thing
118+
// SWIFT_ASSERT_ONLY(--verifyCount);
119+
// } while (!done());
120+
// assert(verifyCount == 0 && "did not do everything");
121+
// }
122+
// };
123+
#ifdef NDEBUG
124+
#define SWIFT_ASSERT_ONLY_DECL(X)
125+
#define SWIFT_ASSERT_ONLY(X) do { } while (false)
126+
#else
127+
#define SWIFT_ASSERT_ONLY_DECL(X) X
128+
#define SWIFT_ASSERT_ONLY(X) do { X; } while (false)
129+
#endif
130+
106131
#endif // SWIFT_BASIC_COMPILER_H

include/swift/SILOptimizer/Utils/PrunedLiveness.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,6 @@
9090

9191
#include "swift/SIL/SILBasicBlock.h"
9292

93-
#ifdef NDEBUG
94-
#define SWIFT_ASSERT_ONLY_MEMBER(X)
95-
#define SWIFT_ASSERT_ONLY(X) do { } while (false)
96-
#else
97-
#define SWIFT_ASSERT_ONLY_MEMBER(X) X
98-
#define SWIFT_ASSERT_ONLY(X) do { X; } while (false)
99-
#endif
100-
10193
namespace swift {
10294

10395
/// Discover "pruned" liveness for an arbitrary set of uses. The client builds
@@ -140,7 +132,7 @@ class PrunedLiveBlocks {
140132
llvm::SmallDenseMap<SILBasicBlock *, bool, 4> liveBlocks;
141133

142134
// Once the first use has been seen, no definitions can be added.
143-
SWIFT_ASSERT_ONLY_MEMBER(bool seenUse = false);
135+
SWIFT_ASSERT_ONLY_DECL(bool seenUse = false);
144136

145137
public:
146138
bool empty() const { return liveBlocks.empty(); }

0 commit comments

Comments
 (0)