Tail Call Optimization in Go

2019-01-18 08:34发布

Does the Go programming language, as of now, optimize tail calls? If not, does it at least optimize tail-recursive calls of a function to itself?

2条回答
闹够了就滚
2楼-- · 2019-01-18 09:07

Everything you can find over the Internet, that "Go supports tailable recursions in some cases", and that was told in mailing list:

It is already there in 6g/8g for certain cases, and in gccgo somewhat more generally.

We do not currently plan to change the language to require that compilers implement tail call optimization in all cases. If you must have a tail call, you use a loop or a goto statement.

To get those cases you'd better dig into golang source, which is open.

查看更多
不美不萌又怎样
3楼-- · 2019-01-18 09:26

It does not. Nor is there any plan to according to the core development team on the mailing list.

查看更多
登录 后发表回答