← Back to Pull requests

base: Compute the copy plan of padded `reinterpret` at compile time #64714

Closed
unknown closed this pull request without merging on Nov 19, 2026 00:02 UTC
View on GitHub
unknown unknown commented on Nov 06, 2026 16:47 UTC
Author

reinterpret between types with different padding (e.g. reinterpret(Tuple{UInt8,UInt32}, ntuple(UInt8, 5))) copied field by field through a packed intermediate buffer, calling fieldoffset/fieldtype at run time. That's slow, and in GPU kernels the jl_get_field_offset calls make it fail to compile.

This PR computes the copies from the two types' non_padding_bytes maps in a :foldable function 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, reinterpret of 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 with unsupported call to an external C function (call to jl_get_field_offset).

Assisted by: Fable 5.2, Sol 6.1

Diff: 282 lines (+211 / -71) across 3 files Reviewer: nhz2 Review duration: 17714m
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
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
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.338
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #64714"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% 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: 39.7% (MEDIUM) · Higher = larger blast radius
39.7%
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: 60.5% · Lower = rushed or shallow review
60.5%
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: 15.7% · Safe to merge
15.7%