Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling functional with IR for Dict getindex raises AssertionError #100

Open
rtjoa opened this issue Jun 16, 2022 · 2 comments
Open

Calling functional with IR for Dict getindex raises AssertionError #100

rtjoa opened this issue Jun 16, 2022 · 2 comments

Comments

@rtjoa
Copy link

rtjoa commented Jun 16, 2022

The following example fails this assert on Julia v1.7.2, IRTools v0.4.6:

using IRTools: IR, functional

ir = IR(typeof(getindex), Dict{String, String}, String)
functional(ir)
@MikeInnes
Copy link
Member

The use of @inbounds return ... here leads to a redundant trailing block in the IR:

1: (%1, %2, %3)
  %4 = Base.ht_keyindex(%2, %3)
  %5 = $(Expr(:inbounds, true))
  %6 = %4 < 0
  br 3 unless %6
2:
  %7 = Base.KeyError(%3)
  %8 = Base.throw(%7)
  return %8
3:
  %9 = Base.getproperty(%2, :vals)
  %10 = Base.getindex(%9, %4)
  %11 = Core.typeassert(%10, $(QuoteNode(String)))
  return %11
4:
  %12 = $(Expr(:inbounds, :pop))

ie block 4 isn't reachable here, and violates our assumptions by not branching anywhere. I guess the Julia compiler has some way to handle this case. I know little about how the :inbounds expression works so I'm not sure if it's safe to simply drop the :pop; for functional we could just remove all :inbounds expressions.

I've been meaning to build some tools for stripping unreachable code, so when I do I'll try to fix this issue as well.

@guyvdbroeck
Copy link

There appear to be more general issues with functional, for example the following code also errors while every block is reachable:

using IRTools: IR, functional
f(x,y) = x && y && error()
ir = IR(typeof(f), Bool, Bool)
functional(ir)

The issue is with the 3 branches in the generated IR:

ir = 1: (%1, %2, %3)
  br 4 unless %2
  br 3 unless %3
  br 2
2:
  %4 = Main.error()
  return %4
3:
  return false
4:
  return false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants