base: Compute the copy plan of padded `reinterpret` at compile time #64714
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 282 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.338
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #64714"
general
weight: 0.35
nhz2
reinterpretbetween types with different padding (e.g.reinterpret(Tuple{UInt8,UInt32}, ntuple(UInt8, 5))) copied field by field through a packed intermediate buffer, callingfieldoffset/fieldtypeat run time. That's slow, and in GPU kernels thejl_get_field_offsetcalls make it fail to compile.This PR computes the copies from the two types'
non_padding_bytesmaps in a:foldablefunction and copies straight from source to destination. The plan is returned as a type parameter (Val((copies...,))): as a tuple value, a plan larger than 256 bytes (about 10 copies) isn't embedded in code by the optimizer, and would silently be recomputed on every call.Supersedes #60415, which has the same goal. First-call compile time (median of 3 fresh processes, #60415 built at its own head) and run time per call (minimum over 50 passes of a loop storing 10,000 results into a vector):
| case | compile: master | this PR | #60415 | run: master | this PR |
|---|---|---|---|---|---|
|
Tuple{UInt8,UInt32}from 5 bytes | 28.5 ms | 27.9 ms | 135 ms | 6.5 ns | 3.8 ns || nested-order case from #60415 review | 30.6 ms | 44.0 ms | 174 ms | 17.6 ns | 1.4 ns |
|
Tuple{Int16, Int8, Int64, Int8, Int64, Int64, Int8}from #60415 | 39.5 ms | 45.1 ms | 156 ms | 363 ns (96 bytes allocated) | 10.9 ns ||
Tuple{UInt8, Int64, Vararg{UInt8,100}}from #60415 | 37.7 ms | 42.1 ms | 136 ms | 336 ns | 21.2 ns ||
Tuple{UInt8, UInt64}from #60415 | 28.9 ms | 28.2 ms | 137 ms | 11.2 ns | 3.6 ns || 33-level nested tuple from #60415 (81 one-byte copies) | 507 ms | 130 ms | 2462 ms | 566 ns | 43.5 ns |
The change is 25 lines added and 52 removed in
base/reinterpretarray.jl, versus about 400 added in #60415, because it builds on the padding byte maps that #62771 introduced. The tests add the nested-order case from the #60415 review, an 81-copy plan that must not allocate, and a check that the plan is not computed and no field offsets are looked up at run time.With this change,
reinterpretof flat, nested and 81-copy padded structs compiles and runs correctly in CUDA.jl kernels on Julia 1.14; without it, all three fail to compile withunsupported call to an external C function (call to jl_get_field_offset).Assisted by: Fable 5.2, Sol 6.1