Skip to content

Commit

Permalink
Avoid depending on extension from within another extension
Browse files Browse the repository at this point in the history
Julia's loading system ought to allow an extension w/ triggers {B,C}
to depend on an extension w/ triggers {A,C}, under the condition that
B depends on A (i.e. the triggers for the second extension are a strict
subset of the triggers for the first extension)

Unfortunately Julia's purely trigger-based mechanism for extensions does
not actually do that. If `C` is the loaded after `{A,B}` then both of
these extensions will trigger "simultaneously" and they will be loaded
in an indeterminate order.

That problem is the same as the "cycle" in
JuliaLang/julia#55557, so-called because pre-
compilation will try to load each of the simultaneously-triggered
extensions "before" the other repeatedly, leading to an ordering cycle.

This works around the problem by removing the inter-extension dependency.
  • Loading branch information
topolarity committed Sep 5, 2024
1 parent 25426ee commit 94fd13b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
13 changes: 4 additions & 9 deletions ext/LazyArraysBandedMatricesExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ import ArrayLayouts: colsupport, rowsupport, materialize!, MatMulVecAdd, MatMulM
layout_getindex, transtype
import LazyArrays: sublayout, symmetriclayout, hermitianlayout, applylayout, cachedlayout, transposelayout,
LazyArrayStyle, ApplyArrayBroadcastStyle, AbstractInvLayout, AbstractLazyLayout, LazyLayouts,
AbstractPaddedLayout, PaddedLayout, PaddedRows, PaddedColumns, CachedArray, CachedMatrix, LazyLayout, BroadcastLayout, ApplyLayout,
AbstractPaddedLayout, PaddedLayout, AbstractLazyBandedLayout, LazyBandedLayout, PaddedRows,
PaddedColumns, CachedArray, CachedMatrix, LazyLayout, BroadcastLayout, ApplyLayout,
paddeddata, resizedata!, broadcastlayout, _broadcastarray2broadcasted, _broadcast_sub_arguments,
arguments, call, applybroadcaststyle, simplify, simplifiable, islazy_layout, lazymaterialize, _broadcast_mul_mul,
triangularlayout, AbstractCachedMatrix
triangularlayout, AbstractCachedMatrix, _mulbanded_copyto!
import Base: BroadcastStyle, similar, copy, broadcasted, getindex, OneTo, oneto, tail, sign, abs
import BandedMatrices: bandedbroadcaststyle, bandwidths, isbanded, bandedcolumns, bandeddata, BandedStyle,
AbstractBandedLayout, AbstractBandedMatrix, BandedColumns, BandedRows, BandedSubBandedMatrix,
_bnds, prodbandwidths, banded_rowsupport, banded_colsupport, _BandedMatrix, _banded_broadcast!,
resize
import LinearAlgebra: AdjOrTrans, UpperOrLowerTriangular, kron

abstract type AbstractLazyBandedLayout <: AbstractBandedLayout end
struct LazyBandedLayout <: AbstractLazyBandedLayout end

symmetriclayout(::AbstractLazyBandedLayout) = SymmetricLayout{LazyBandedLayout}()
hermitianlayout(::Type{<:Real}, ::AbstractLazyBandedLayout) = SymmetricLayout{LazyBandedLayout}()
hermitianlayout(::Type{<:Complex}, ::AbstractLazyBandedLayout) = HermitianLayout{LazyBandedLayout}()
Expand Down Expand Up @@ -257,10 +255,7 @@ BroadcastLayout(::BroadcastBandedLayout{F}) where F = BroadcastLayout{F}()


# functions that satisfy f(0,0) == 0

const _ZERO_OPS = (:*, :-, :+, :sign, :abs)

for op in _ZERO_OPS
for op in (:*, :-, :+, :sign, :abs)
@eval broadcastlayout(::Type{typeof($op)}, ::BandedLayouts) = BroadcastBandedLayout{typeof($op)}()
end

Expand Down
12 changes: 4 additions & 8 deletions ext/LazyArraysBlockBandedMatricesExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import LazyArrays: sublayout, symmetriclayout, hermitianlayout, transposelayout,
islazy_layout, arguments, call, applylayout, broadcastlayout, applybroadcaststyle,
BroadcastMatrix, _broadcastarray2broadcasted, _cache, resizedata!, simplifiable,
AbstractLazyLayout, LazyArrayStyle, LazyLayout, ApplyLayout, BroadcastLayout, AbstractInvLayout,
_mul_args_colsupport, _mul_args_rowsupport, _mat_mul_arguments,
CachedArray, _broadcast_sub_arguments, simplify, lazymaterialize
_mul_args_colsupport, _mul_args_rowsupport, _mat_mul_arguments, LazyBandedLayout,
CachedArray, _broadcast_sub_arguments, simplify, lazymaterialize, _mulbanded_copyto!
import BlockBandedMatrices: AbstractBlockBandedLayout, AbstractBandedBlockBandedLayout, blockbandwidths, subblockbandwidths,
bandedblockbandedbroadcaststyle, bandedblockbandedcolumns, BandedBlockBandedColumns, BandedBlockBandedRows,
BlockRange1, Block1, BlockIndexRange1, BlockBandedColumns, BlockBandedRows, BandedBlockBandedLayout
Expand All @@ -22,11 +22,6 @@ import Base: similar, copy, broadcasted
import ArrayLayouts: materialize!, MatMulVecAdd, sublayout, colsupport, rowsupport, copyto!_layout, mulreduce, inv_layout,
OnesLayout, AbstractFillLayout

const LazyArraysBandedMatricesExt = Base.get_extension(LazyArrays, :LazyArraysBandedMatricesExt)
const LazyBandedLayout = LazyArraysBandedMatricesExt.LazyBandedLayout
const _mulbanded_copyto! = LazyArraysBandedMatricesExt._mulbanded_copyto!


abstract type AbstractLazyBlockBandedLayout <: AbstractBlockBandedLayout end
abstract type AbstractLazyBandedBlockBandedLayout <: AbstractBandedBlockBandedLayout end

Expand Down Expand Up @@ -157,7 +152,8 @@ const BroadcastBlockBandedLayouts{F} = Union{BroadcastBlockBandedLayout{F},Broad
blockbandwidths(B::BroadcastMatrix) = blockbandwidths(broadcasted(B))
subblockbandwidths(B::BroadcastMatrix) = subblockbandwidths(broadcasted(B))

for op in LazyArraysBandedMatricesExt._ZERO_OPS
# functions that satisfy f(0,0) == 0
for op in (:*, :-, :+, :sign, :abs)
@eval begin
broadcastlayout(::Type{typeof($op)}, ::BlockBandedLayouts) = BroadcastBlockBandedLayout{typeof($op)}()
broadcastlayout(::Type{typeof($op)}, ::BandedBlockBandedLayouts) = BroadcastBandedBlockBandedLayout{typeof($op)}()
Expand Down
6 changes: 6 additions & 0 deletions src/LazyArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ map(::typeof(length), A::BroadcastVector{<:Vcat,Type{Vcat}}) = broadcast(+,map.(
broadcasted(::LazyArrayStyle{1}, ::typeof(length), A::BroadcastVector{OneTo{Int},Type{OneTo}}) = A.args[1]
broadcasted(::LazyArrayStyle{1}, ::typeof(length), A::BroadcastVector{<:Fill,Type{Fill},<:NTuple{2,Any}}) = A.args[2]

# types for use by extensions
function _mulbanded_copyto! end

abstract type AbstractLazyBandedLayout <: AbstractBandedLayout end
struct LazyBandedLayout <: AbstractLazyBandedLayout end

if !isdefined(Base, :get_extension)
include("../ext/LazyArraysStaticArraysExt.jl")
include("../ext/LazyArraysBandedMatricesExt.jl")
Expand Down

0 comments on commit 94fd13b

Please sign in to comment.