{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/8853","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/8853/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/8853/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/8853/events","html_url":"https://github.com/JuliaLang/julia/issues/8853","id":47245357,"number":8853,"title":"recursive stagedfunction and type inference","user":{"login":"Jutho","id":4162102,"avatar_url":"https://avatars.githubusercontent.com/u/4162102?v=3","gravatar_id":"","url":"https://api.github.com/users/Jutho","html_url":"https://github.com/Jutho","followers_url":"https://api.github.com/users/Jutho/followers","following_url":"https://api.github.com/users/Jutho/following{/other_user}","gists_url":"https://api.github.com/users/Jutho/gists{/gist_id}","starred_url":"https://api.github.com/users/Jutho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jutho/subscriptions","organizations_url":"https://api.github.com/users/Jutho/orgs","repos_url":"https://api.github.com/users/Jutho/repos","events_url":"https://api.github.com/users/Jutho/events{/privacy}","received_events_url":"https://api.github.com/users/Jutho/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2014-10-30T08:49:01Z","updated_at":"2015-01-18T12:28:35Z","closed_at":null,"body":"I was trying to explore the possibility of using staged functions with tuple arguments in a recursive manner, to reimplement e.g. #6517 . Therefore, I first tried to implement the Fibonacci function using staged functions, where I have an `nt::NTuple{N,Int}` argument, where the first integer `nt[1]` corresponds to the Fibonacci index/parameter, and I just do some trivial operations on the other values in the tuple.\r\n\r\nThis is the code\r\n```julia\r\nstagedfunction fibrec{N}(nt::NTuple{N,Int})\r\n    statements=[Expr(:(=),symbol(\"n$i\"),Expr(:call,:+,Expr(:ref,:nt,i),i-1)) for i=1:N]\r\n    args1=Any[symbol(\"n$i\") for i=1:N]\r\n    args1[1]=Expr(:call,:-,:n1,1)\r\n    args2=Any[symbol(\"n$i\") for i=1:N]\r\n    args2[1]=Expr(:call,:-,:n1,2)\r\n    rec1=Expr(:call,:fibrec,Expr(:tuple,args1...))\r\n    rec2=Expr(:call,:fibrec,Expr(:tuple,args2...))\r\n    \r\n    ex=Expr(:if,:(n1<2),:(return n1),Expr(:return,Expr(:call,:+,rec1,rec2)))\r\n    return Expr(:block,statements...,ex)\r\nend\r\n```\r\nand for something like `N=3` this returned expression is\r\n```julia\r\n    n1 = nt[1] + 0\r\n    n2 = nt[2] + 1\r\n    n3 = nt[3] + 2\r\n    if n1 < 2\r\n        return n1\r\n    else \r\n        return fibrec((n1 - 1,n2,n3)) + fibrec((n1 - 2,n2,n3))\r\n    end\r\n```\r\nwhich looks ok.\r\n\r\nHowever, trying to run gives rise to\r\n```\r\nERROR: stack overflow\r\n in _methods at ./reflection.jl:100\r\n in _methods at /usr/local/julia/usr/lib/julia/sys.dylib\r\n in _methods at ./reflection.jl:117\r\n in _methods at /usr/local/julia/usr/lib/julia/sys.dylib\r\n in _methods at ./reflection.jl:117\r\n in _methods at /usr/local/julia/usr/lib/julia/sys.dylib\r\n in _methods at ./reflection.jl:97\r\n in _methods at /usr/local/julia/usr/lib/julia/sys.dylib\r\n in abstract_call_gf at ./inference.jl:664\r\n in abstract_call at ./inference.jl:831\r\n in abstract_eval_call at ./inference.jl:923\r\n in abstract_eval at ./inference.jl:948\r\n in abstract_interpret at ./inference.jl:1103\r\n in typeinf at ./inference.jl:1432\r\n in typeinf at /usr/local/julia/usr/lib/julia/sys.dylib\r\n in typeinf at ./inference.jl:1238\r\n in abstract_call_gf at ./inference.jl:718\r\n in abstract_call at ./inference.jl:831\r\n in abstract_eval_call at ./inference.jl:923\r\n in abstract_eval at ./inference.jl:948\r\n in abstract_eval_arg at ./inference.jl:887\r\n in abstract_eval_call at ./inference.jl:899\r\n in abstract_eval at ./inference.jl:948\r\n in abstract_eval_arg at ./inference.jl:887\r\n in typeinf at ./inference.jl:1495\r\n in typeinf at /usr/local/julia/usr/lib/julia/sys.dylib\r\n in typeinf at ./inference.jl:1238\r\n...\r\n```\r\nand from there on it repeats this last block starting at `in abstract_call_gf at ./inference.jl:718` many times."},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/70406487","html_url":"https://github.com/JuliaLang/julia/issues/8853#issuecomment-70406487","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/8853","id":70406487,"user":{"login":"Jutho","id":4162102,"avatar_url":"https://avatars.githubusercontent.com/u/4162102?v=3","gravatar_id":"","url":"https://api.github.com/users/Jutho","html_url":"https://github.com/Jutho","followers_url":"https://api.github.com/users/Jutho/followers","following_url":"https://api.github.com/users/Jutho/following{/other_user}","gists_url":"https://api.github.com/users/Jutho/gists{/gist_id}","starred_url":"https://api.github.com/users/Jutho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jutho/subscriptions","organizations_url":"https://api.github.com/users/Jutho/orgs","repos_url":"https://api.github.com/users/Jutho/repos","events_url":"https://api.github.com/users/Jutho/events{/privacy}","received_events_url":"https://api.github.com/users/Jutho/received_events","type":"User","site_admin":false},"created_at":"2015-01-18T12:28:35Z","updated_at":"2015-01-18T12:28:35Z","body":"Maybe somebody with some better knowledge of how type inference can briefly explain me if code_typed and actually calling a function take the same code path through type inference or not. "}}