Skip to content

Commit

Permalink
Merge pull request #35 from willtebbutt/wct/boundscheck
Browse files Browse the repository at this point in the history
Boundscheck implementation + test
  • Loading branch information
dfdx authored Jul 29, 2023
2 parents a76107a + af5ae5f commit 272b1ac
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Umlaut"
uuid = "92992a2b-8ce5-4a9c-bb9d-58be9a7dc841"
authors = ["Andrei Zhabinski <[email protected]>"]
version = "0.5.1"
version = "0.5.2"

[deps]
CompilerPluginTools = "6b7a57c9-7cc1-4fdf-b7f5-e857abae3638"
Expand Down
8 changes: 8 additions & 0 deletions src/trace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ function rewrite_special_cases(st::Expr)
if Meta.isexpr(ex, :splatnew)
ex = Expr(:call, __splatnew__, ex.args...)
end
# replace :($(Expr(:boundscheck))) with just `true`
if Meta.isexpr(ex, :boundscheck)
ex = true
end
# same for arguments
if ex isa Expr
ex.args = [Meta.isexpr(arg, :boundscheck) ? true : arg for arg in ex.args]
end
return Meta.isexpr(st, :(=)) ? Expr(:(=), st.args[1], ex) : ex
end
rewrite_special_cases(st) = st
Expand Down
23 changes: 23 additions & 0 deletions test/test_trace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ end

###############################################################################

@eval _alt_getindex(x::Vector, i) = Base.arrayref($(Expr(:boundscheck)), x, i)
@eval function _boundscheck_foo()
v = $(Expr(:boundscheck))
return v ? 1 : 0
end

@testset "trace: :boundscheck" begin
@testset "boundscheck as argument" begin
x = randn(5)
val, tape = trace(_alt_getindex, x, 1)
@test val == getindex(x, 1)
@test play!(tape, getindex, x, 1) == getindex(x, 1)
end

@testset "boundscheck as rhs statement" begin
val, tape = trace(_boundscheck_foo)
@test val == _boundscheck_foo()
@test play!(tape, _boundscheck_foo) == val
end
end

###############################################################################


@testset "trace: bcast" begin
# bcast
Expand Down

0 comments on commit 272b1ac

Please sign in to comment.