Skip to content

Commit 1502d7f

Browse files
feat: wrap function in @inbounds if checkbounds = false
1 parent a119204 commit 1502d7f

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/build_function.jl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ function _build_function(target::JuliaTarget, op, args...;
119119
(wrap_code !== nothing) && (fun = wrap_code(fun))
120120
conv(fun, states)
121121
end
122-
122+
if !checkbounds
123+
@assert Meta.isexpr(expr, :function)
124+
expr.args[2] = :(@inbounds begin; $(expr.args[2]); end)
125+
end
123126
if expression == Val{true}
124127
expr
125128
else
@@ -165,6 +168,12 @@ function _build_function(target::JuliaTarget, op::Union{Arr, ArrayOp}, args...;
165168
end) |> LiteralExpr
166169
end
167170
ip_expr = conv(Func(dargs, [], op_body), states)
171+
if !checkbounds
172+
@assert Meta.isexpr(oop_expr, :function)
173+
oop_expr.args[2] = :(@inbounds begin; $(oop_expr.args[2]); end)
174+
@assert Meta.isexpr(ip_expr, :function)
175+
ip_expr.args[2] = :(@inbounds begin; $(ip_expr.args[2]); end)
176+
end
168177
if expression == Val{true}
169178
oop_expr, ip_expr
170179
else
@@ -325,11 +334,18 @@ function _build_function(target::JuliaTarget, rhss::AbstractArray, args...;
325334
ip_expr = wrap_code[2](ip_expr)
326335
end
327336

337+
oop_expr, ip_expr = conv(oop_expr, states), conv(ip_expr, states)
338+
if !checkbounds
339+
@assert Meta.isexpr(oop_expr, :function)
340+
oop_expr.args[2] = :(@inbounds begin; $(oop_expr.args[2]); end)
341+
@assert Meta.isexpr(ip_expr, :function)
342+
ip_expr.args[2] = :(@inbounds begin; $(ip_expr.args[2]); end)
343+
end
328344
if expression == Val{true}
329-
return conv(oop_expr, states), conv(ip_expr, states)
345+
return oop_expr, ip_expr
330346
else
331-
return _build_and_inject_function(expression_module, conv(oop_expr, states)),
332-
_build_and_inject_function(expression_module, conv(ip_expr, states))
347+
return _build_and_inject_function(expression_module, oop_expr),
348+
_build_and_inject_function(expression_module, ip_expr)
333349
end
334350
end
335351

0 commit comments

Comments
 (0)