← Back to Pull requests

extend `dataids` semantics, with the goal of obviating non-generic methods of `mightalias` #60984

Open
nsajko opened this pull request with 171 lines diff across 5 files
View on GitHub
nsajko nsajko commented on Feb 10, 2026 17:48 UTC
Author

Very WIP.

There are multiple issues with the aliasing detection machinery. This PR only attempts to make dataids more expressive, to make special methods of mightalias unnecessary. It attempts complete backwards compatibility, even though dataids is not public API yet. Other PRs might follow, for example to replace the current unsafe defaults of dataids or mightalias with something safer and more consistent.

Some issues to cross-reference:

https://github.com/JuliaLang/julia/issues/8087

https://github.com/JuliaLang/julia/issues/26865

Not directly relevant, perhaps for a future PR: https://github.com/JuliaLang/julia/issues/50820

* https://github.com/JuliaLang/julia/issues/51753

Diff: 171 lines (+96 / -75) across 5 files Reviewer: nsajko Review duration: 404917m
All Vouch review confidence checks passed
Residual risk 0.11 = Change Risk (0.61) × (1 − Review Confidence (0.82)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.61 · 171 lines diff across 5 files
0.61
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.94 · 5 substantive comment(s)
0.94
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
81%
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.308
Self Review self_review
0.140
Real PR Conversation Timeline
6 items
nsajko nsajko commented on code on Feb 10, 2026 18:03 UTC
Code Review
base/subarray.jl:1
@@ -104,7 +104,12 @@ function parentindices end
 parentindices(a::AbstractArray) = map(oneto, size(a))
 
 ## Aliasing detection
-dataids(A::SubArray) = (dataids(A.parent)..., _splatmap(dataids, A.indices)...)
+function dataids(A::SubArray)
+    read_write_dataids = dataids(A.parent)
+    read_only_dataids_1 = _splatmap(dataids, A.indices)
+    read_only_dataids_2 = map(_canonicalize_dataid_as_readonly, read_only_dataids_1)

TODO: one more necessary refinement here is to rely on the "extent" feature of DataID. Without that I suppose the already existing tests will fail.

mbauman mbauman commented on Feb 10, 2026 18:49 UTC
Contributor

I really appreciate the addition of some sort of readable state; that's a huge improvement. I'm not as convinced about putting it into the type system, but could be convinced if the benchmarks are compelling. It just seems like it'd make it harder to work with the (now heterogeneous) tuples of DataIDs... and then also harder and more expensive to subsequently resolve what I find to be the biggest shortcoming: the generic dataid method.

Using (and computing) extents can give some wins, but finding the extents themselves can also be surprisingly expensive. IMO, I don't find the non-generic mightalias methods so problematic. They're pure optimizations (and improved answers) for known common cases — including cases that still exist here with extents. For example, the common @view A[1, :] has worthless extents, but it's trivial to see that it doesn't alias against A[2, :].

nsajko nsajko commented on Feb 10, 2026 21:21 UTC
Author

I really appreciate the addition of some sort of readable state; that's a huge improvement. I'm not as convinced about putting it into the type system, but could be convinced if the benchmarks are compelling.

If the additional information is not in the type system, then necessarily additional work has to be done at run time in _isdisjoint, so there is necessarily a performance regression, for some use case at least. My goal is to enable types to opt into implementing the more powerful variant of dataids, without causing any run time performance regression for types that do not choose to opt in.

Do you disagree with this goal? Or is it something else?

It just seems like it'd make it harder to work with the (now heterogeneous) tuples of DataIDs

True, however I do not think it is possible to keep the tuples homogeneous while keeping backwards compatibility.

and then also harder and more expensive to subsequently resolve what I find to be the biggest shortcoming: the generic dataid method.

You are referring to a hypothetical fallback method dataids(::Any)/dataids(::AbstractArray) with a non-trivial implementation? That would necessarily have to use reflection, right? TBH I feel bad about that direction. I would feel better with a hypothetical dataids fallback with a trivial and conservative implementation that would guarantee safety for Base.mightalias. Something like dataids(::Any) = (missing,), with adjustments to isdisjoint to interpret missing as "aliases anything and everything". And then make dataids public API, so most types would implement it, as long as they're not already isbits or similar.

Also, I am not sure why do you say that putting the "is readonly"/"is writable" bit into the type system would make the fallback method of dataids more expensive or more difficult to implement? After all, it is always safe to fall back to "data is writable"/"data is not readonly".

Using (and computing) extents can give some wins, but finding the extents themselves can also be surprisingly expensive.

As above, putting the additional information into the type domain means that each method of dataids only opts into the new costs if they choose so explicitly. Whoever implements a dataids method may choose not to specify an extent if they deem that finding the extent might turn out to be excessively costly.

IMO, I don't find the non-generic mightalias methods so problematic.

I dislike the potential for the creeping combinatoric explosion of methods definitions, when various combinations of types are accounted for. And the fact that the special mightalias methods hijack coverage away from dataids. However, I guess you are right, I suppose we might want to add back the methods I got rid of in the initial commit, before merging this PR, as necessary, if the PR will be merged.

including cases that still exist here with extents. For example, the common @view A[1, :] has worthless extents, but it's trivial to see that it doesn't alias against A[2, :].

I suppose dataids/DataID could handle that particular case as-is, by merely relaxing the supertype constraint for the optional_extent field from Union{Nothing, UnitRange{UInt}} to Union{Nothing, UnitRange{UInt}, StepRange{UInt, UInt}}. Or even relax it further to some supertype like Union{Nothing, OrdinalRange{UInt, UInt}}? Will play with this.

nsajko nsajko commented on Feb 11, 2026 15:01 UTC
Author

This PR now kinda depends on PR #60998, which is blocked on issue #47577.

mbauman mbauman commented on Feb 11, 2026 16:01 UTC
Contributor

My main concern is one of prioritization: this needs to be a very fast path, and that there are many _other_ deficiencies that I find to be simultaneously more important and harder. If this _also_ paints a path towards addressing the other challenges, then I am in! But I actually think this will make subsequent improvements harder.

My initial vision here was that the dataids intersection test could eventually become the first tier in a multi-tier system. We first check to see if any data segments are the same, and — if so — we then ask for a more refined answer. That's effectively what the non-generic mightalias methods aim to do, but in an ad-hoc manner.

Perhaps one significant improvement would be to introduce to a more concrete function whose name _actually describes_ what the generic mightalias currently does: perhaps something like shares_dataids.

Then it becomes easier in my mind to begin layering additional functions atop this atom — including ones that more clearly specify which argument will be written to.

Reviewers
Assignees
nsajko nsajko
Labels
risk: low confidence: 81.6% 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: 60.7% (MEDIUM) · Higher = larger blast radius
60.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: 81.6% · Lower = rushed or shallow review
81.6%
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: 11.2% · Safe to merge
11.2%