{"action":"closed","issue":{"url":"https://api.github.com/repos/jrevels/Cassette.jl/issues/71","repository_url":"https://api.github.com/repos/jrevels/Cassette.jl","labels_url":"https://api.github.com/repos/jrevels/Cassette.jl/issues/71/labels{/name}","comments_url":"https://api.github.com/repos/jrevels/Cassette.jl/issues/71/comments","events_url":"https://api.github.com/repos/jrevels/Cassette.jl/issues/71/events","html_url":"https://github.com/jrevels/Cassette.jl/issues/71","id":349253810,"node_id":"MDU6SXNzdWUzNDkyNTM4MTA=","number":71,"title":"Const-prop through tuple","user":{"login":"maleadt","id":383068,"node_id":"MDQ6VXNlcjM4MzA2OA==","avatar_url":"https://avatars3.githubusercontent.com/u/383068?v=4","gravatar_id":"","url":"https://api.github.com/users/maleadt","html_url":"https://github.com/maleadt","followers_url":"https://api.github.com/users/maleadt/followers","following_url":"https://api.github.com/users/maleadt/following{/other_user}","gists_url":"https://api.github.com/users/maleadt/gists{/gist_id}","starred_url":"https://api.github.com/users/maleadt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maleadt/subscriptions","organizations_url":"https://api.github.com/users/maleadt/orgs","repos_url":"https://api.github.com/users/maleadt/repos","events_url":"https://api.github.com/users/maleadt/events{/privacy}","received_events_url":"https://api.github.com/users/maleadt/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2018-08-09T19:10:57Z","updated_at":"2018-12-18T22:32:11Z","closed_at":"2018-12-18T22:32:11Z","author_association":"CONTRIBUTOR","body":"The following fails to generate efficient code:\r\n\r\n```julia\r\ninner(::Type{Bool}, i) = nothing\r\nouter(I...) = inner(Bool, I...)\r\n\r\nusing Cassette\r\nCassette.@context Ctx\r\n\r\nf = (args...) -> Cassette.overdub(Ctx(), outer, args...)\r\ncode_warntype(f, Tuple{Int})\r\n```\r\n\r\n```\r\nBody::ANY\r\n10 1 ─ %1 = Cassette.overdub::Core.Compiler.Const(Cassette.overdub, false)\r\n   │   %2 = (getfield)(args, 1)::Int64\r\n   │   %3 = invoke %1($(QuoteNode(Cassette.Context{nametype(Ctx),Nothing,Cassette.NoPass,Nothing,Nothing}(nametype(Ctx)(), nothing, Cassette.NoPass(), nothing, nothing)))::Cassette.Context{nametype(Ctx),Nothing,Cassette.NoPass,Nothing,Nothing}, outer::typeof(outer), %2::Int64)::ANY\r\n   └──      return %3\r\n```\r\n\r\n... whereas without overdubbing, we simply get:\r\n\r\n```\r\nBody::Nothing\r\n2 1 ─     return\r\n```\r\n\r\nChecking the code for `overdub` reveals why we get the invoke:\r\n\r\n```julia\r\ncode_warntype(Cassette.overdub, Tuple{typeof(Ctx()), typeof(outer), Int})\r\n```\r\n\r\n```\r\nBody::ANY\r\n2 1 ─ %1  = (Core.getfield)(##overdub_arguments#369, 2)::Int64\r\n  │   %2  = (Core.tuple)(%1)::Tuple{Int64}\r\n  └──       goto #3 if not true\r\n  2 ─ %4  = Core.tuple::Core.Compiler.Const(tuple, false)\r\n  │   %5  = Main.Bool::Core.Compiler.Const(Bool, false)\r\n  └── %6  = (%4)(%5)::Tuple{DataType}\r\n  3 ─ %7  = φ (#2 => %6, #1 => $(QuoteNode(Cassette.OverdubInstead())))::UNION{OVERDUBINSTEAD, TUPLE{DATATYPE}}\r\n  │   %8  = π (%7, Core.Compiler.Const((Bool,), false))\r\n  └──       goto #5 if not true\r\n  4 ─ %10 = Core._apply::typeof(Core._apply)\r\n  │   %11 = (%10)(tuple, %8, %2)::Tuple{DataType,Int64}\r\n  │   %12 = (getfield)(%11, 1)::DATATYPE\r\n  │   %13 = (getfield)(%11, 2)::Int64\r\n  └── %14 = (Cassette.overdub)($(QuoteNode(Cassette.Context{nametype(Ctx),Nothing,Cassette.NoPass,Nothing,Nothing}(nametype(Ctx)(), nothing, Cassette.NoPass(), nothing, nothing))), inner, %12, %13)::ANY\r\n  5 ─ %15 = φ (#4 => %14, #3 => $(QuoteNode(Cassette.OverdubInstead())))::ANY\r\n  └──       return %15\r\n```\r\n\r\nLooks like a failure to const-prop the `Bool` argument through the argument tuple. But then again, the second element of the tuple isn't const, and I'm not sure whether that can be expressed with `Compiler.Const`.\r\n\r\nThis specific pattern arises with `checkbounds(::Array, ::Integer)` which calls to `checkbounds(Bool, ...)` (ie. passing a `Type{Bool}`), so this probably penalizes quite a lot of code as soon as it indexes arrays."}}
{"actor":{"display_login":"jrevels"}}