@@ -68,6 +68,7 @@ function pushexpr!(ex::Expr, mk::MaybeKnown)
68
68
end
69
69
pushexpr! (ex:: Expr , x:: Union{Symbol,Expr} ) = (push! (ex. args, x); nothing )
70
70
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 )
71
72
MaybeKnown (x:: Integer ) = MaybeKnown (convert (Int, x), Symbol (" ##UNDEFINED##" ), true )
72
73
MaybeKnown (x:: Integer , default:: Int ) = MaybeKnown (x)
73
74
MaybeKnown (x:: Symbol , default:: Int ) = MaybeKnown (default, x, false )
@@ -926,19 +927,20 @@ function add_block!(ls::LoopSet, ex::Expr, elementbytes::Int, position::Int)
926
927
push! (ls, x, elementbytes, position)
927
928
end
928
929
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)
939
941
end
940
- else
941
- static_literals! (expr )
942
+ elseif ex isa Expr
943
+ makestatic! (ex )
942
944
end
943
945
end
944
946
expr
@@ -957,7 +959,7 @@ function add_loop_bound!(
957
959
upper:: Bool ,
958
960
step:: Bool ,
959
961
):: MaybeKnown
960
- maybestatic ! (bound)
962
+ makestatic ! (bound)
961
963
N = gensym! (
962
964
ls,
963
965
string (itersym) *
@@ -966,17 +968,6 @@ function add_loop_bound!(
966
968
pushprepreamble! (ls, Expr (:(= ), N, bound))
967
969
MaybeKnown (N, upper ? 1024 : 1 )
968
970
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
980
971
function range_loop! (
981
972
ls:: LoopSet ,
982
973
itersym:: Symbol ,
@@ -1021,7 +1012,7 @@ function oneto_loop!(ls::LoopSet, r::Expr, itersym::Symbol)::Loop
1021
1012
rangename = lensym = Symbol (" " )
1022
1013
MaybeKnown (convert (Int, otN):: Int , 0 )
1023
1014
else
1024
- otN isa Expr && maybestatic ! (otN)
1015
+ otN isa Expr && makestatic ! (otN)
1025
1016
lensym = N = gensym! (ls, " loop" * string (itersym))
1026
1017
rangename = gensym! (ls, " range" )
1027
1018
pushprepreamble! (ls, Expr (:(= ), N, otN))
@@ -1084,7 +1075,7 @@ function misc_loop!(
1084
1075
Expr (
1085
1076
:(= ),
1086
1077
rangename,
1087
- Expr (:call , lv (:canonicalize_range ), :(@inbounds $ (static_literals ! (r)))),
1078
+ Expr (:call , lv (:canonicalize_range ), :(@inbounds $ (makestatic ! (r)))),
1088
1079
),
1089
1080
)
1090
1081
pushprepreamble! (
0 commit comments