summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2022-01-07 12:47:07 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-01-11 19:44:33 -0500
commit7ca43a3fb315abf172a6f7ff2bb4cf4303017e24 (patch)
tree3c488faf681c0fe47954ff74c15edac20a74ee09
parent19b13698f5afe6ab497eb2e2169cb9782a933f93 (diff)
downloadhaskell-7ca43a3fb315abf172a6f7ff2bb4cf4303017e24.tar.gz
Change assertions in Stats.c to warnings (and introduce WARN macro)
ASSERT should be used in situations where something very bad will happen later on if a certain invariant doesn't hold. The idea is that IF we catch the assertion earlier then it will be easier to work out what's going on at that point rather than at some indeterminate point in the future of the program. The assertions in Stats.c do not obey this philsophy and it is quite annoying if you are running a debug build (or a ticky compiler) and one of these assertions fails right at the end of your program, before the ticky report is printed out so you don't get any profiling information. Given that nothing terrible happens if these assertions are not true, or at least the terrible thing will happen in very close proximity to the assertion failure, these assertions use the new WARN macro which prints the assertion failure to stdout but does not exit the program. Of course, it would be better to fix these metrics to not trigger the assertion in the first place but if they did fail again in the future it is frustrating to be bamboozled in this manner. Fixes #20899
-rw-r--r--rts/RtsMessages.c6
-rw-r--r--rts/Stats.c14
-rw-r--r--rts/include/Rts.h13
3 files changed, 26 insertions, 7 deletions
diff --git a/rts/RtsMessages.c b/rts/RtsMessages.c
index 9ecd831a83..8ece485854 100644
--- a/rts/RtsMessages.c
+++ b/rts/RtsMessages.c
@@ -73,6 +73,12 @@ errorBelch(const char*s, ...)
}
void
+_warnFail(const char*filename, unsigned int linenum)
+{
+ errorBelch("ASSERTION FAILED: file %s, line %u\n", filename, linenum);
+}
+
+void
verrorBelch(const char*s, va_list ap)
{
(*errorMsgFn)(s,ap);
diff --git a/rts/Stats.c b/rts/Stats.c
index ed6695ad45..7abe2f7417 100644
--- a/rts/Stats.c
+++ b/rts/Stats.c
@@ -1275,7 +1275,7 @@ stat_exitReport (void)
Time exit_gc_cpu = stats.gc_cpu_ns - start_exit_gc_cpu;
Time exit_gc_elapsed = stats.gc_elapsed_ns - start_exit_gc_elapsed;
- ASSERT(exit_gc_elapsed > 0);
+ WARN(exit_gc_elapsed > 0);
sum.exit_cpu_ns = end_exit_cpu
- start_exit_cpu
@@ -1284,7 +1284,7 @@ stat_exitReport (void)
- start_exit_elapsed
- exit_gc_elapsed;
- ASSERT(sum.exit_elapsed_ns >= 0);
+ WARN(sum.exit_elapsed_ns >= 0);
stats.mutator_cpu_ns = start_exit_cpu
- end_init_cpu
@@ -1294,7 +1294,7 @@ stat_exitReport (void)
- end_init_elapsed
- (stats.gc_elapsed_ns - exit_gc_elapsed);
- ASSERT(stats.mutator_elapsed_ns >= 0);
+ WARN(stats.mutator_elapsed_ns >= 0);
if (stats.mutator_cpu_ns < 0) { stats.mutator_cpu_ns = 0; }
@@ -1302,7 +1302,7 @@ stat_exitReport (void)
// and subtracting, so the parts should add up to the total exactly.
// Note that stats->total_ns is captured a tiny bit later than
// end_exit_elapsed, so we don't use it here.
- ASSERT(stats.init_elapsed_ns // INIT
+ WARN(stats.init_elapsed_ns // INIT
+ stats.mutator_elapsed_ns // MUT
+ stats.gc_elapsed_ns // GC
+ sum.exit_elapsed_ns // EXIT
@@ -1319,7 +1319,7 @@ stat_exitReport (void)
// This assertion is probably not necessary; make sure the
// subdivision with PROF also makes sense
- ASSERT(stats.init_elapsed_ns // INIT
+ WARN(stats.init_elapsed_ns // INIT
+ stats.mutator_elapsed_ns // MUT
+ stats.gc_elapsed_ns // GC
+ sum.exit_elapsed_ns // EXIT
@@ -1401,7 +1401,7 @@ stat_exitReport (void)
- sum.exit_cpu_ns)
/ TimeToSecondsDbl(stats.cpu_ns);
- ASSERT(sum.productivity_cpu_percent >= 0);
+ WARN(sum.productivity_cpu_percent >= 0);
sum.productivity_elapsed_percent =
TimeToSecondsDbl(stats.elapsed_ns
@@ -1410,7 +1410,7 @@ stat_exitReport (void)
- sum.exit_elapsed_ns)
/ TimeToSecondsDbl(stats.elapsed_ns);
- ASSERT(sum.productivity_elapsed_percent >= 0);
+ WARN(sum.productivity_elapsed_percent >= 0);
for(uint32_t g = 0; g < RtsFlags.GcFlags.generations; ++g) {
const generation* gen = &generations[g];
diff --git a/rts/include/Rts.h b/rts/include/Rts.h
index e3471cf333..2399f8ce7f 100644
--- a/rts/include/Rts.h
+++ b/rts/include/Rts.h
@@ -120,12 +120,20 @@ extern "C" {
void _assertFail(const char *filename, unsigned int linenum)
GNUC3_ATTRIBUTE(__noreturn__);
+void _warnFail(const char *filename, unsigned int linenum);
+
#define CHECK(predicate) \
if (RTS_LIKELY(predicate)) \
/*null*/; \
else \
_assertFail(__FILE__, __LINE__)
+#define CHECKWARN(predicate) \
+ if (RTS_LIKELY(predicate)) \
+ /*null*/; \
+ else \
+ _warnFail(__FILE__, __LINE__)
+
#define CHECKM(predicate, msg, ...) \
if (RTS_LIKELY(predicate)) \
/*null*/; \
@@ -143,11 +151,16 @@ void _assertFail(const char *filename, unsigned int linenum)
do { CHECK(predicate); } while(0)
#define ASSERTM(predicate,msg,...) \
do { CHECKM(predicate, msg, ##__VA_ARGS__); } while(0)
+#define WARN(predicate) \
+ do { CHECKWARN(predicate); } while(0)
+
#else
#define ASSERT(predicate) \
do { (void) sizeof(predicate); } while(0)
#define ASSERTM(predicate,msg,...) \
do { (void) sizeof(predicate); (void) sizeof(msg); } while(0)
+#define WARN(predicate) \
+ do { (void) sizeof(predicate); } while(0)
#endif /* DEBUG */
/*