← Back to Pull requests

Fix jl_gc_wb_genericmemory_copy_boxed not advancing src/dest ptr #61852

Merged
xal-0 merged 6 files (42 lines) on May 30, 2026 01:21 UTC
View on GitHub
xal-0 xal-0 commented on May 19, 2026 21:36 UTC
Author

Claude Opus 4.7 xhigh spotted this one when I was making some unrelated changes (I'm impressed!). #57252/378a42508d4 introduced this bug when extracting the code for jl_gc_wb_genericmemory_copy_boxed from jl_genericmemory_copyto: the caller assumes src_p and dest_p will be updated to point to the remaining elements memmove_refs must copy, but we no longer mutate them. I had Claude turn them into pointers, so they are updated like before.

Nifty PoC:

dest = Any[nothing for i=1:16]
for i in 1:2
GC.gc(true)
    GC.gc(false)
end
src = vcat(Any[nothing], Any[Ref(100 * i) for i=1:15])
copyto!(dest, src)
for (i, (x, y)) in enumerate(zip(dest, src))
    if x !== y
        println("dest[$i] = $x, expected src[$i] = $y")
    end
end

Diff: 42 lines (+31 / -11) across 6 files Reviewer: topolarity Review duration: 14624m
All Vouch review confidence checks passed
Residual risk 0.06 = Change Risk (0.38) × (1 − Review Confidence (0.85)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.38 · 42 lines diff across 6 files
0.38
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.85 · 5 substantive comment(s)
0.85
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
84%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.225
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
10 items
adienes adienes commented on May 19, 2026 21:59 UTC
Contributor

any reason not to use the poc above as a regression test?

xal-0 xal-0 commented on May 20, 2026 17:46 UTC
Author

Might as well!

gbaraldi gbaraldi commented on code on May 20, 2026 18:17 UTC
Code Review
test/gc.jl:1
@@ -65,6 +65,7 @@ end
     run_gctest("gc/linkedlist.jl")
     run_gctest("gc/objarray.jl")
     run_gctest("gc/chunks.jl")
+    run_gctest("gc/copyto.jl")

Not to be annoying but this is technically a codegen check and not a gc one. (jl_gc_wb_genericmemory_copy_boxed) is a horrible name but needed because gcs need to implement their own if they have write barriers that matter

topolarity topolarity commented on code on May 20, 2026 20:40 UTC
Code Review
src/gc-wb-stock.h:1
@@ -59,8 +61,11 @@ STATIC_INLINE void jl_gc_wb_genericmemory_copy_boxed(const jl_value_t *dest_owne
                         break;
                     }
                 }
-                src_p += done;
-                dest_p += done;
+                // advance caller's pointers past the elements we just
+                // copied so the trailing memmove_refs picks up where we
+                // left off
+                *src_pp = src_p + done;

Doesn't this still have an off-by-one bug? Not really observable, but still

JeffBezanson JeffBezanson commented on code on May 21, 2026 19:36 UTC
Code Review
src/gc-wb-stock.h:1
@@ -59,8 +61,11 @@ STATIC_INLINE void jl_gc_wb_genericmemory_copy_boxed(const jl_value_t *dest_owne
                         break;
                     }
                 }
-                src_p += done;
-                dest_p += done;
+                // advance caller's pointers past the elements we just
+                // copied so the trailing memmove_refs picks up where we
+                // left off
+                *src_pp = src_p + done;

I think it's correct? If we copy all the items, this should end up 1 past the end.

xal-0 xal-0 commented on code on May 21, 2026 23:16 UTC
Code Review
test/gc.jl:1
@@ -65,6 +65,7 @@ end
     run_gctest("gc/linkedlist.jl")
     run_gctest("gc/objarray.jl")
     run_gctest("gc/chunks.jl")
+    run_gctest("gc/copyto.jl")

Is there a better place for it to live? It could go in arrayops.jl, I suppose.

topolarity topolarity commented on code on May 21, 2026 23:32 UTC
Code Review
src/gc-wb-stock.h:1
@@ -59,8 +61,11 @@ STATIC_INLINE void jl_gc_wb_genericmemory_copy_boxed(const jl_value_t *dest_owne
                         break;
                     }
                 }
-                src_p += done;
-                dest_p += done;
+                // advance caller's pointers past the elements we just
+                // copied so the trailing memmove_refs picks up where we
+                // left off
+                *src_pp = src_p + done;

Right, but if we break we copy an element twice. Not that it really matters now that we at least advance the pointers consistently.

xal-0 xal-0 commented on code on May 26, 2026 20:19 UTC
Code Review
src/gc-wb-stock.h:1
@@ -59,8 +61,11 @@ STATIC_INLINE void jl_gc_wb_genericmemory_copy_boxed(const jl_value_t *dest_owne
                         break;
                     }
                 }
-                src_p += done;
-                dest_p += done;
+                // advance caller's pointers past the elements we just
+                // copied so the trailing memmove_refs picks up where we
+                // left off
+                *src_pp = src_p + done;

This existed in the pre-#57252 version too, but it's nice to have it fixed.

topolarity topolarity approved these changes on May 29, 2026 20:09 UTC
Approved Reviewer

Approved these changes.

Reviewers
Assignees
xal-0 xal-0
Labels
risk: low confidence: 84.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 37.8% (MEDIUM) · Higher = larger blast radius
37.8%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 84.7% · Lower = rushed or shallow review
84.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 5.8% · Safe to merge
5.8%