Skip to content

Commit 48ac9e2

Browse files
dennisYatuninclaude
andcommitted
Resolve the two new method ambiguities flagged by Aqua on Julia 1.11
The DataStyle x DataStyle method was ambiguous with the DataStyle x AbstractArrayStyle{0} method because the existing DataStyle{0} disambiguator did not cover their full type intersection: typeintersect drops the DataLayout bound on the second style's layout type, so the disambiguator needs an unconstrained typevar there (and the diagonal bound on the first argument). The scalar-broadcast copyto! was ambiguous with BlockArrays' copyto! for AbstractBlockStyle{0}, resolved with an explicit method like the existing StaticArrayStyle{0} one. Verified with Aqua.detect_ambiguities filtered as in test/aqua.jl: 27 -> 25 on Julia 1.11.9 (CI failed at 27 > 26) and 25 -> 24 on Julia 1.10, with exactly the two new pairs removed and none added; dispatch behavior verified unchanged for 0-dimensional style combinations. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent ee00ebe commit 48ac9e2

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/DataLayouts/DataLayouts.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module DataLayouts
33
import Base: @propagate_inbounds
44
import LLVM: unsafe_load
55
import StaticArrays
6+
import BlockArrays
67
import Adapt
78

89
import ClimaComms

src/DataLayouts/broadcast.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ Broadcast.BroadcastStyle(::DataStyle{<:Any, D1}, ::DataStyle{<:Any, D2}) where {
2121
Broadcast.BroadcastStyle(style::DataStyle, ::Broadcast.Style{Tuple}) = style
2222
Broadcast.BroadcastStyle(style::DataStyle, ::Broadcast.AbstractArrayStyle{0}) = style
2323
Broadcast.BroadcastStyle(style::DataStyle, ::Broadcast.DefaultArrayStyle{0}) = style
24-
Broadcast.BroadcastStyle(style::DataStyle, ::DataStyle{0}) = style
24+
# The unconstrained typevar D2 is required for this method to cover the full
25+
# intersection of the two ambiguous signatures above (typeintersect drops the
26+
# DataLayout bound on the second style's layout type).
27+
Broadcast.BroadcastStyle(
28+
style::DataStyle{N, D1},
29+
::DataStyle{0, D2},
30+
) where {N, D1 <: DataLayout{<:Any, N}, D2} = style
2531

2632
# Enable automatic nested broadcasting over supported types of iterators.
2733
@inline Broadcast.broadcastable(data::DataLayout) =

src/DataLayouts/loops.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,13 @@ end
222222
# scalar broadcast runs in a pointwise loop. materialize! attaches dest's axes so Base
223223
# evaluates at every dest index, but foreach_point's single-point views lack dest indices,
224224
# so the axes are removed and the broadcast runs at index 1 (Base's instantiate likewise
225-
# leaves scalar broadcasts axis-free). StaticArrayStyle{0} avoids a StaticArrays ambiguity.
226-
for S in (:(<:Broadcast.AbstractArrayStyle{0}), :(<:StaticArrays.StaticArrayStyle{0}))
225+
# leaves scalar broadcasts axis-free). The StaticArrayStyle{0} and AbstractBlockStyle{0}
226+
# methods avoid ambiguities with StaticArrays and BlockArrays.
227+
for S in (
228+
:(<:Broadcast.AbstractArrayStyle{0}),
229+
:(<:StaticArrays.StaticArrayStyle{0}),
230+
:(<:BlockArrays.AbstractBlockStyle{0}),
231+
)
227232
@eval @inline Base.copyto!(dest::DataLayout, bc::Broadcast.Broadcasted{$S}; kwargs...) =
228233
if bc.f === identity && isone(length(bc.args)) && Broadcast.isflat(bc)
229234
@inbounds arg = first(bc.args)

0 commit comments

Comments
 (0)