Conversation
The interprocedural address-space narrowing folded two concerns: undoing Julia's pre-JuliaLang/julia#53687 lowering of `Ptr` arguments to integers (the typed-pointer shim), and narrowing generic pointer parameters to a specific space. Split them. Phase 1 (`convert_intptr_args!`, gated on `VERSION < v"1.12.0-DEV.225"`) turns integer-image `Ptr` parameters back into generic pointers, so Phase 2 narrows pointers with no integer-specific handling -- the same code path for typed and opaque pointers. The shim is now isolated, and deletable in one go once 1.12 is the minimum. The gate is the Julia version rather than `supports_typed_pointers`, because "`Ptr` lowered to an integer" and "LLVM uses typed pointers" are separate switches: they agree on releases, but opaque pointers could be enabled while `Ptr` is still passed as an integer. Both phases share a `rewrite_parameters!` engine (clone the signature, rewrite the call sites, per-parameter policy via closures). Also prune the dead self- `bitcast` that `clone_into!` leaves on the new function, which the re- processing across phases would otherwise trip over. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Changing a function's signature is the same dance everywhere -- create a new function, reconstruct each changed argument on entry so the body is unchanged, clone the body over, then erase the old function -- but it was open-coded in every backend's argument-rewriting pass, each re-deriving the same workaround for `clone_into!` dropping attributes on retargeted parameters. Factor the mechanical part into `clone_with_converted_args!` and `replace_function!` (utils.jl) and use them from the four passes whose parameters map 1:1: Metal's address-space narrowing, the GCN byref-to-constant and SPIR-V byval-to-pointer kernel-argument lowerings, and the kernel-state-to-reference pass in irgen. The parts that genuinely differ -- which parameters change, how each is reconstructed, attribute handling, and (only Metal's pass) rewriting call sites -- stay in the callers. Left open-coded: `pass_by_reference!` (can drop ghost arguments, so parameters aren't 1:1) and the two byval/byref passes that reattach attributes inside the conversion loop, where the timing is entangled with `clone_into!`. Net ~110 fewer lines; codegen tests pass for all backends on typed-pointer (1.11) and opaque-pointer (1.12) builds. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #827 +/- ##
==========================================
+ Coverage 79.04% 79.27% +0.22%
==========================================
Files 25 25
Lines 4587 4516 -71
==========================================
- Hits 3626 3580 -46
+ Misses 961 936 -25 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Also create a shared helper for a common rewriting operation.