{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/15946","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/15946/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/15946/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/15946/events","html_url":"https://github.com/JuliaLang/julia/issues/15946","id":149584356,"number":15946,"title":"type-inference penalty for loops over conditional collections","user":{"login":"stevengj","id":2913679,"avatar_url":"https://avatars.githubusercontent.com/u/2913679?v=3","gravatar_id":"","url":"https://api.github.com/users/stevengj","html_url":"https://github.com/stevengj","followers_url":"https://api.github.com/users/stevengj/followers","following_url":"https://api.github.com/users/stevengj/following{/other_user}","gists_url":"https://api.github.com/users/stevengj/gists{/gist_id}","starred_url":"https://api.github.com/users/stevengj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevengj/subscriptions","organizations_url":"https://api.github.com/users/stevengj/orgs","repos_url":"https://api.github.com/users/stevengj/repos","events_url":"https://api.github.com/users/stevengj/events{/privacy}","received_events_url":"https://api.github.com/users/stevengj/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/JuliaLang/julia/labels/performance","name":"performance","color":"d7e102"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-04-19T21:06:15Z","updated_at":"2016-04-20T03:24:33Z","closed_at":"2016-04-20T03:24:33Z","body":"In some cases it is nice to have a loop like `for x in (condition ? A : B) ... `, but it appears that this defeats type inference.\r\n\r\nFor example, in #15945 it turned out that I needed to traverse the same loop in a different order depending on the sign of a variable.  (Because I wanted to loop from big to small terms in a series, enabling me to stop the loop early when the series terms become small enough.)\r\n\r\ne.g. `@code_warntype` shows `Any` types for\r\n```\r\nfunction foo(x)\r\n    s = 0.0\r\n    for i = (x < 0 ? (10:-1:1) : (1:10))\r\n        s += 1/i^2\r\n    end\r\n    return s\r\nend\r\n```\r\n\r\nOf course, I could always just write two loops here, but it is annoying to have to write an identical loop body twice — I wish the compiler could do this for me."},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/212235813","html_url":"https://github.com/JuliaLang/julia/issues/15946#issuecomment-212235813","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/15946","id":212235813,"user":{"login":"stevengj","id":2913679,"avatar_url":"https://avatars.githubusercontent.com/u/2913679?v=3","gravatar_id":"","url":"https://api.github.com/users/stevengj","html_url":"https://github.com/stevengj","followers_url":"https://api.github.com/users/stevengj/followers","following_url":"https://api.github.com/users/stevengj/following{/other_user}","gists_url":"https://api.github.com/users/stevengj/gists{/gist_id}","starred_url":"https://api.github.com/users/stevengj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevengj/subscriptions","organizations_url":"https://api.github.com/users/stevengj/orgs","repos_url":"https://api.github.com/users/stevengj/repos","events_url":"https://api.github.com/users/stevengj/events{/privacy}","received_events_url":"https://api.github.com/users/stevengj/received_events","type":"User","site_admin":false},"created_at":"2016-04-20T03:24:33Z","updated_at":"2016-04-20T03:24:33Z","body":"Fair enough."}}