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

Regression in type inference in closures #16048

Closed
davidanthoff opened this issue Apr 25, 2016 · 4 comments
Closed

Regression in type inference in closures #16048

davidanthoff opened this issue Apr 25, 2016 · 4 comments

Comments

@davidanthoff
Copy link
Contributor

This is the repo code:

function get_f()
    a = 0.2

    function f2()
        b = 2/a

        return b
    end

    return f2
end

f = get_f()

@code_warntype f()

On julia 0.4 I get:

Variables:
  b::Float64

Body:
  begin  # C:\Users\anthoff\source\4sD.jl\test.jl, line 5:
      b = (Base.box)(Base.Float64,(Base.div_float)((Base.box)(Float64,(Base.sitofp)(Float64,2)),a::Float64)) # C:\Users\anthoff\source\4sD.jl\test.jl, line 7:
      return b::Float64
  end::Float64

On julia 0.5 I get:

Variables:
  #self#::#f2#1
  b::Any

Body:
  begin  # C:\Users\anthoff\source\4sD.jl\test.jl, line 5:
      b::Any = (2 / (top(getfield))((top(getfield))(#self#::#f2#1,:a)::Any,:contents)::Any)::Any # C:\Users\anthoff\source\4sD.jl\test.jl, line 7:
      return b::Any
  end::Any
@yuyichao
Copy link
Contributor

Dup of #15276

@davidanthoff
Copy link
Contributor Author

Is this a dup? My problem has no arrays or comprehensions in it at all. Even if this has the same root cause, isn't this a much simpler repo than #15276?

@yuyichao
Copy link
Contributor

It is a dup. Both of them are caused by closure lowering. It is very easy to construct simple repros and there's no reason to keep multiple issue around for exactly the same issue.

julia> function f()
           a = 2
           (()->a)()
       end
f (generic function with 1 method)

julia> @code_warntype f()
Variables:
  #self#::#f
  a::Core.Box
  #1::##1#2

Body:
  begin  # REPL[1], line 2:
      a::Core.Box = $(Expr(:new, :((top(getfield))(Core,:Box)::Type{Core.Box})))
      (top(setfield!))(a::Core.Box,:contents,2)::Int64 # REPL[1], line 3:
      GenSym(0) = a::Core.Box
      return (top(getfield))(GenSym(0),:contents)::Any
  end::Any

@davidanthoff
Copy link
Contributor Author

Alright, thanks for looking into it!

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

2 participants