Skip to content

solve type stability of DiskIndex #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 10, 2025
Merged

solve type stability of DiskIndex #267

merged 4 commits into from
Aug 10, 2025

Conversation

rafaqz
Copy link
Collaborator

@rafaqz rafaqz commented Jul 8, 2025

Closes #266

I did a bit of code cleanup to understand what was happening, removed all broadcasts over tuples.

But the final thing that worked was solving this :
JuliaLang/julia#48059 (comment)

With really dumb methods like these that somehow trick the compilers recursion detection :

# This makes 3 arg type stable
function _resolve_indices(chunks::Tuple{<:Any}, i::Tuple{<:Any}, indices_pre::DiskIndex, strategy::BatchStrategy)
    inow = first(i)
    indices_new, chunksrem = process_index(inow, chunks, strategy)
    return merge_index(indices_pre, indices_new)
end
# This makes 4 arg type stable
function _resolve_indices(chunks::Tuple{<:Any,<:Any}, i::Tuple{<:Any,<:Any}, indices_pre::DiskIndex, strategy::BatchStrategy)
    inow = first(i)
    indices_new, chunksrem = process_index(inow, chunks, strategy)
    return _resolve_indices(chunksrem, tail(i), merge_index(indices_pre, indices_new), strategy)
end
# ... out to 4 Anys in the Tuples for 6 args of type stability

@rafaqz rafaqz requested a review from meggart July 8, 2025 13:41
@lupemba
Copy link

lupemba commented Aug 9, 2025

Could me merge and release this PR?

@rafaqz
Copy link
Collaborator Author

rafaqz commented Aug 10, 2025

Can you review it? ;)

@lupemba
Copy link

lupemba commented Aug 10, 2025

Can you review it? ;)

I did some small test with the PR and had a closer look at the code.

  • There are probably a more elegant way to implement the specific _resolve_indices methods but it is hard to get correct. I gave it a try using Val{dimension} for dispatch but I couldn't get it to work.
  • I don't understand all possible ways of indexing in DiskArrrays and I am therefore unsure if all possible ways of indexing are inferred now.

My review, this looks good to merge. It fixes the concrete issues with type inference and it doesn't have any negative side effects. There might be some corner cases that are missed but I still think DiskArrays is better with this PR.

@rafaqz rafaqz merged commit 42ae9b9 into main Aug 10, 2025
10 checks passed
@rafaqz rafaqz deleted the type_stability branch August 10, 2025 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DiskIndex is not inferred
2 participants