{"action":"opened","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/22376","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/22376/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/22376/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/22376/events","html_url":"https://github.com/JuliaLang/julia/issues/22376","id":236091939,"number":22376,"title":"Multiple broadcast expressions.","user":{"login":"joshbode","id":878107,"avatar_url":"https://avatars0.githubusercontent.com/u/878107?v=3","gravatar_id":"","url":"https://api.github.com/users/joshbode","html_url":"https://github.com/joshbode","followers_url":"https://api.github.com/users/joshbode/followers","following_url":"https://api.github.com/users/joshbode/following{/other_user}","gists_url":"https://api.github.com/users/joshbode/gists{/gist_id}","starred_url":"https://api.github.com/users/joshbode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshbode/subscriptions","organizations_url":"https://api.github.com/users/joshbode/orgs","repos_url":"https://api.github.com/users/joshbode/repos","events_url":"https://api.github.com/users/joshbode/events{/privacy}","received_events_url":"https://api.github.com/users/joshbode/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-06-15T06:42:49Z","updated_at":"2017-06-15T06:42:49Z","closed_at":null,"body":"The code expansion for broadcast expressions such as `f.(g.(x))` looks to be incorrect (involving `:composite_type`, for example). For some vector types, this is also leading to incorrect return types (see JuliaStats/DataArrays.jl#263).\r\n\r\n```julia\r\n0.6.0-rc3.0> expand(:(f.(g.(x))))\r\n:($(Expr(:thunk, CodeInfo(:(begin\r\n        $(Expr(:thunk, CodeInfo(:(begin\r\n        global ##13#14\r\n        const ##13#14\r\n        $(Expr(:composite_type, Symbol(\"##13#14\"), :((Core.svec)()), :((Core.svec)()), :(Core.Function), :((Core.svec)()), false, 0))\r\n        return\r\n    end))))\r\n        $(Expr(:method, false, :((Core.svec)((Core.svec)(##13#14, Core.Any), (Core.svec)())), CodeInfo(:(begin\r\n        #temp#@_3 = g(#temp#@_2)\r\n        return f(#temp#@_3)\r\n    end)), false))\r\n        #13 = $(Expr(:new, Symbol(\"##13#14\")))\r\n        SSAValue(0) = #13\r\n        return (Base.broadcast)(SSAValue(0), x)\r\n    end)))))\r\n```\r\nversus the more intuitive expansion when the inner expression is put inside a `begin...end` block:\r\n```julia\r\n0.6.0-rc3.0> expand(:(f.(begin g.(x) end)))\r\n:($(Expr(:thunk, CodeInfo(:(begin\r\n        # meta: location REPL[33] # REPL[33], line 1:\r\n        # meta: pop location\r\n        SSAValue(0) = (Base.broadcast)(g, x)\r\n        return (Base.broadcast)(f, SSAValue(0))\r\n    end)))))\r\n```\r\n\r\nIt is also very slow, even for very simple expressions:\r\n```julia\r\n0.6.0-rc3.0> f(x) = x;\r\n0.6.0-rc3.0> g(x) = x;\r\n0.6.0-rc3.0> x = [1,2,3];\r\n```\r\n(each ran a few times to burn-in)\r\n```julia\r\n0.6.0-rc3.0> @time f.(g.(x));\r\n0.063864 seconds (4.26 k allocations: 237.958 KiB)\r\n```\r\ncompared to:\r\n```julia\r\n0.6.0-rc3.0> @time f.(begin g.(x) end);\r\n0.000213 seconds (58 allocations: 2.563 KiB)\r\n```"}}
{"actor":{"display_login":"joshbode"}}