wingo pushed a commit to branch wip-whippet
in repository guile.

commit 162c5364b3dd61d0a41f50bf22da300c589ce1a6
Author: Andy Wingo <wi...@igalia.com>
AuthorDate: Thu Jul 3 10:21:31 2025 +0200

    nofl: Assert no forwarded object after GC in debug mode
---
 src/nofl-space.h | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/nofl-space.h b/src/nofl-space.h
index 37f707176..82315aaec 100644
--- a/src/nofl-space.h
+++ b/src/nofl-space.h
@@ -1374,6 +1374,13 @@ nofl_metadata_byte_trace_kind(struct nofl_space *space, 
uint8_t byte)
   }
 }
 
+static void
+nofl_assert_not_forwarded(struct gc_ref ref)
+{
+  struct gc_atomic_forward fwd = gc_atomic_forward_begin(ref);
+  GC_ASSERT_EQ(fwd.state, GC_FORWARDING_STATE_NOT_FORWARDED);
+}
+
 static void
 nofl_space_verify_sweepable_blocks(struct nofl_space *space,
                                    struct nofl_block_list *list)
@@ -1396,11 +1403,13 @@ nofl_space_verify_sweepable_blocks(struct nofl_space 
*space,
           granules++;
         GC_ASSERT(meta[granules - 1] & NOFL_METADATA_BYTE_END);
 
-        if (nofl_metadata_byte_trace_kind (space, byte) == GC_TRACE_PRECISELY) 
{
+        if (nofl_metadata_byte_trace_kind(space, byte) == GC_TRACE_PRECISELY) {
           size_t trace_bytes;
           gc_trace_object(obj, NULL, NULL, NULL, &trace_bytes);
           size_t trace_granules = nofl_size_to_granules(trace_bytes);
           GC_ASSERT_EQ(granules, trace_granules);
+
+          nofl_assert_not_forwarded(obj);
         }
 
         meta += granules;
@@ -1436,11 +1445,13 @@ nofl_space_verify_swept_blocks(struct nofl_space *space,
           granules++;
         GC_ASSERT(meta[granules - 1] & NOFL_METADATA_BYTE_END);
 
-        if (nofl_metadata_byte_trace_kind (space, byte) == GC_TRACE_PRECISELY) 
{
+        if (nofl_metadata_byte_trace_kind(space, byte) == GC_TRACE_PRECISELY) {
           size_t trace_bytes;
           gc_trace_object(obj, NULL, NULL, NULL, &trace_bytes);
           size_t trace_granules = nofl_size_to_granules(trace_bytes);
           GC_ASSERT_EQ(granules, trace_granules);
+
+          nofl_assert_not_forwarded(obj);
         }
 
         meta += granules;

Reply via email to