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

Collision of generated names in generated functions #12474

Closed
yuyichao opened this issue Aug 5, 2015 · 0 comments · Fixed by #12497
Closed

Collision of generated names in generated functions #12474

yuyichao opened this issue Aug 5, 2015 · 0 comments · Fixed by #12497

Comments

@yuyichao
Copy link
Contributor

yuyichao commented Aug 5, 2015

To reproduce:

@generated function f(::Any)
    :(for i in 1
      end)
end

println(@code_typed f(1.2))

Output is attached below. Somehow the automatically generated names in the body of the generated function uses a independent counter from the original function and this causes the generated variable names to collide.

Since the generated names in the argument lists are never used, this may not cause any behavioral difference but it does cause the variable to be lifted to Any and introduce all kinds of boxing etc. (See the Any[symbol("#s1"),Any,2] in the code_typed output below)

(@code_warntype can show that the variable is not type stable but it is almost impossible to tell from it's output why this is happening...)

Output

Any[:($(Expr(:lambda, Any[:(#s1::Any)], Any[Any[Any[symbol("#s1"),Any,2],Any[:i,Int64,18]],Any[],Any[Int64,Tuple{Int64,Bool},Int64],Any[]], :(begin  # /home/yuyichao/projects/explore/julia/generated_anon_val/generated_anon_val.jl, line 4:
        GenSym(0) = 1
        #s1 = false
        unless (Base.box)(Base.Bool,(Base.not_int)(#s1::Bool))::Bool goto 1
        2: 
        GenSym(2) = GenSym(0)
        i = GenSym(2)
        #s1 = true
        3: 
        unless (Base.box)(Base.Bool,(Base.not_int)((Base.box)(Base.Bool,(Base.not_int)(#s1::Bool))::Bool))::Bool goto 2
        1: 
        0: 
        return
    end::Void))))]
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

Successfully merging a pull request may close this issue.

1 participant