Can the F # function be considered tail recursive, it uses the TailCall.net opcode

Since .net has a TailCall opcode , can this be used to determine if the F # function is really tail recursive?

If true, has anyone done a VS add-in that identifies the functions of the tail and not the tail?

+4
source share
2 answers

See this F # team blog post for a brief summary of how F # compiles tail calls.

In short,

  • Direct recursive tail calls are usually converted to loops.
  • Mutual recursion and indirect non-recursive tail calls usually turn into .NET tail calls.

but see the full post for all the details.

+6
source

Yes, if the compiler issues a command to call tail , that call will be tail recursive (like CLR 4, but there are still some exceptions where it will not actually be tail recursive). But this does not necessarily mean that the entire function is tail recursive. For example, I can imagine that the QuickSort function is compiled so that the first recursive call is not tail recursive, and the second -.

In addition, just because some function does not contain the tail command, it does not necessarily mean that it is not tail recursive. The JIT compiler can recognize a tail call even without a tail statement and optimize it as such.

What's more, the F # compiler sometimes compiles recursive functions in a non-recursive way. This is somewhat different from the usual tail call optimization, and the tail statement is not used, but the overall effect is similar.

+3
source

Source: https://habr.com/ru/post/1401282/


All Articles