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

Closure and ccall lowering causes unneeded boxing #21906

Closed
yuyichao opened this issue May 16, 2017 · 1 comment
Closed

Closure and ccall lowering causes unneeded boxing #21906

yuyichao opened this issue May 16, 2017 · 1 comment
Assignees
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage) regression Regression in behavior compared to a previous version

Comments

@yuyichao
Copy link
Contributor

Another special case of #15276 though also related to ccall lowering.

The ccall and the normal function call should have the same effect on closure lowering but apparently not. The ccall causes the second range to be boxed but not when it's a normal function call.

julia> function test0()
           range1 = 1
           threadsfor_fun1() = range1
           ccall(:jl_breakpoint, Void, (Any,), threadsfor_fun1)
           range2 = 2
           threadsfor_fun2() = range2
           ccall(:jl_breakpoint, Void, (Any,), threadsfor_fun2)
       end
test0 (generic function with 1 method)

julia>

julia> function test1()
           range1 = 1
           threadsfor_fun1() = range1
           identity(threadsfor_fun1)
           range2 = 2
           threadsfor_fun2() = range2
           identity(threadsfor_fun2)
       end
test1 (generic function with 1 method)

julia>

julia> @code_lowered test0()
CodeInfo(:(begin
        nothing
        range2 = (Core.Box)()
        range1 = 1 # line 3:
        threadsfor_fun1 = $(Expr(:new, :((Core.apply_type)(Main.#threadsfor_fun1#1, (Core.typeof)(range1))), :(range1))) # line 4:
        $(Expr(:foreigncall, :(:jl_breakpoint), Void, svec(Any), :(threadsfor_fun1), 0)) # line 5:
        (Core.setfield!)(range2, :contents, 2) # line 6:
        threadsfor_fun2 = $(Expr(:new, :(Main.#threadsfor_fun2#2), :(range2))) # line 7:
        return $(Expr(:foreigncall, :(:jl_breakpoint), Void, svec(Any), :(threadsfor_fun2), 0))
    end))

julia> @code_lowered test1()
CodeInfo(:(begin
        nothing
        range1 = 1 # line 3:
        threadsfor_fun1 = $(Expr(:new, :((Core.apply_type)(Main.#threadsfor_fun1#3, (Core.typeof)(range1))), :(range1))) # line 4:
        (Main.identity)(threadsfor_fun1) # line 5:
        range2 = 2 # line 6:
        threadsfor_fun2 = $(Expr(:new, :((Core.apply_type)(Main.#threadsfor_fun2#4, (Core.typeof)(range2))), :(range2))) # line 7:
        return (Main.identity)(threadsfor_fun2)
    end))

This is a regression compare to 0.5.

@yuyichao yuyichao added compiler:lowering Syntax lowering (compiler front end, 2nd stage) regression Regression in behavior compared to a previous version labels May 16, 2017
@yuyichao
Copy link
Contributor Author

@JeffBezanson JeffBezanson self-assigned this May 16, 2017
tkelman pushed a commit that referenced this issue May 17, 2017
JeffBezanson added a commit that referenced this issue May 17, 2017
fix #21906, `ccall` causes unnecessary variable `Box`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage) regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

2 participants