Skip to content

Commit 0bc0da9

Browse files
committed
a few updates toward Static 0.7
1 parent 23588f6 commit 0bc0da9

File tree

4 files changed

+23
-2340
lines changed

4 files changed

+23
-2340
lines changed

src/broadcast.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ function _strides_expr(@nospecialize(s), @nospecialize(x), R::Vector{Int}, D::Ve
238238
q
239239
end
240240
@generated function _strides(
241-
s::Tuple{Vararg{Integer,N}},
242-
x::Tuple{Vararg{Integer,N}},
241+
s::Tuple{Vararg{Union{StaticInt,Integer},N}},
242+
x::Tuple{Vararg{Union{StaticInt,Integer},N}},
243243
::Val{R},
244244
::Val{D},
245245
) where {N,R,D}

src/modeling/graphs.jl

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function pushexpr!(ex::Expr, mk::MaybeKnown)
6868
end
6969
pushexpr!(ex::Expr, x::Union{Symbol,Expr}) = (push!(ex.args, x); nothing)
7070
pushexpr!(ex::Expr, x::Integer) = (push!(ex.args, staticexpr(convert(Int, x))); nothing)
71+
pushexpr!(ex::Expr, @nospecialize(x::StaticInt)) = (push!(ex.args, x); nothing)
7172
MaybeKnown(x::Integer) = MaybeKnown(convert(Int, x), Symbol("##UNDEFINED##"), true)
7273
MaybeKnown(x::Integer, default::Int) = MaybeKnown(x)
7374
MaybeKnown(x::Symbol, default::Int) = MaybeKnown(default, x, false)
@@ -926,19 +927,20 @@ function add_block!(ls::LoopSet, ex::Expr, elementbytes::Int, position::Int)
926927
push!(ls, x, elementbytes, position)
927928
end
928929
end
929-
function maybestatic!(expr::Expr)
930-
if expr.head === :call
931-
f = first(expr.args)
932-
if f === :length
933-
expr.args[1] = GlobalRef(ArrayInterface, :static_length)
934-
elseif f === :size && length(expr.args) == 3
935-
i = expr.args[3]
936-
if i isa Integer
937-
expr.args[1] = GlobalRef(ArrayInterface, :size)
938-
expr.args[3] = staticexpr(convert(Int, i)::Int)
930+
function makestatic!(expr)
931+
expr isa Expr || return expr
932+
for i = eachindex(expr.args)
933+
ex = expr.args[i]
934+
if ex isa Int
935+
expr.args[i] = staticexpr(ex)
936+
elseif ex isa Symbol
937+
if ex === :length
938+
expr.args[i] = GlobalRef(ArrayInterface, :static_length)
939+
elseif Base.sym_in(ex, (:axes, :size))
940+
expr.args[i] = GlobalRef(ArrayInterface, ex)
939941
end
940-
else
941-
static_literals!(expr)
942+
elseif ex isa Expr
943+
makestatic!(ex)
942944
end
943945
end
944946
expr
@@ -957,7 +959,7 @@ function add_loop_bound!(
957959
upper::Bool,
958960
step::Bool,
959961
)::MaybeKnown
960-
maybestatic!(bound)
962+
makestatic!(bound)
961963
N = gensym!(
962964
ls,
963965
string(itersym) *
@@ -966,17 +968,6 @@ function add_loop_bound!(
966968
pushprepreamble!(ls, Expr(:(=), N, bound))
967969
MaybeKnown(N, upper ? 1024 : 1)
968970
end
969-
static_literals!(s::Symbol) = s
970-
function static_literals!(q::Expr)
971-
for (i, ex) enumerate(q.args)
972-
if ex isa Number
973-
q.args[i] = staticexpr(ex)
974-
elseif ex isa Expr
975-
static_literals!(ex)
976-
end
977-
end
978-
q
979-
end
980971
function range_loop!(
981972
ls::LoopSet,
982973
itersym::Symbol,
@@ -1021,7 +1012,7 @@ function oneto_loop!(ls::LoopSet, r::Expr, itersym::Symbol)::Loop
10211012
rangename = lensym = Symbol("")
10221013
MaybeKnown(convert(Int, otN)::Int, 0)
10231014
else
1024-
otN isa Expr && maybestatic!(otN)
1015+
otN isa Expr && makestatic!(otN)
10251016
lensym = N = gensym!(ls, "loop" * string(itersym))
10261017
rangename = gensym!(ls, "range")
10271018
pushprepreamble!(ls, Expr(:(=), N, otN))
@@ -1084,7 +1075,7 @@ function misc_loop!(
10841075
Expr(
10851076
:(=),
10861077
rangename,
1087-
Expr(:call, lv(:canonicalize_range), :(@inbounds $(static_literals!(r)))),
1078+
Expr(:call, lv(:canonicalize_range), :(@inbounds $(makestatic!(r)))),
10881079
),
10891080
)
10901081
pushprepreamble!(

0 commit comments

Comments
 (0)