Skip to content

Commit

Permalink
feat: wrap function in @inbounds if checkbounds = false
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Dec 25, 2024
1 parent a119204 commit 1502d7f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/build_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ function _build_function(target::JuliaTarget, op, args...;
(wrap_code !== nothing) && (fun = wrap_code(fun))
conv(fun, states)
end

if !checkbounds
@assert Meta.isexpr(expr, :function)
expr.args[2] = :(@inbounds begin; $(expr.args[2]); end)
end
if expression == Val{true}
expr
else
Expand Down Expand Up @@ -165,6 +168,12 @@ function _build_function(target::JuliaTarget, op::Union{Arr, ArrayOp}, args...;
end) |> LiteralExpr
end
ip_expr = conv(Func(dargs, [], op_body), states)
if !checkbounds
@assert Meta.isexpr(oop_expr, :function)
oop_expr.args[2] = :(@inbounds begin; $(oop_expr.args[2]); end)
@assert Meta.isexpr(ip_expr, :function)
ip_expr.args[2] = :(@inbounds begin; $(ip_expr.args[2]); end)
end
if expression == Val{true}
oop_expr, ip_expr
else
Expand Down Expand Up @@ -325,11 +334,18 @@ function _build_function(target::JuliaTarget, rhss::AbstractArray, args...;
ip_expr = wrap_code[2](ip_expr)
end

oop_expr, ip_expr = conv(oop_expr, states), conv(ip_expr, states)
if !checkbounds
@assert Meta.isexpr(oop_expr, :function)
oop_expr.args[2] = :(@inbounds begin; $(oop_expr.args[2]); end)
@assert Meta.isexpr(ip_expr, :function)
ip_expr.args[2] = :(@inbounds begin; $(ip_expr.args[2]); end)
end
if expression == Val{true}
return conv(oop_expr, states), conv(ip_expr, states)
return oop_expr, ip_expr
else
return _build_and_inject_function(expression_module, conv(oop_expr, states)),
_build_and_inject_function(expression_module, conv(ip_expr, states))
return _build_and_inject_function(expression_module, oop_expr),
_build_and_inject_function(expression_module, ip_expr)
end
end

Expand Down

0 comments on commit 1502d7f

Please sign in to comment.