RE: Tail calls of funs not optimized?

John Högberg <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <HE1PR0701MB279306E07B9EACCEF9FCA449F67D9@HE1PR0701MB2793.eurprd07.prod.outlook.com>
If you're curious about how it's done you can find a quick overview under "Transformation rules" in beam_makeops.md [1]. The specific rule is in ops.tab [2].

Regards,
John Högberg

[1] https://github.com/erlang/otp/blob/7f37605f8bb24519bd51b15184cc27d5583cddb7/erts/emulator/internal_doc/beam_makeops.md 
[2] https://github.com/erlang/otp/blob/7f37605f8bb24519bd51b15184cc27d5583cddb7/erts/emulator/beam/emu/ops.tab#L1034+L1040

-----Original Message-----
From: erlang-questions <[email protected]> On Behalf Of Björn Gustavsson
Sent: Tuesday, March 30, 2021 10:14 AM
To: Ondřej Adamovský <[email protected]>
Cc: erlang-questions <[email protected]>
Subject: Re: Tail calls of funs not optimized?

On Tue, Mar 30, 2021 at 8:46 AM Ondřej Adamovský <[email protected]> wrote:

> Can somebody explain to me why? Or if this still is optimized somehow, then how?

Calls to funs in the tail of a function will be rewritten by the loader to make the calls tail-recursive.

In OTP 23 or earlier, call erts_debug:df(Mod) to produce a text file named Mod.dis with the disassembled loaded instructions.

In the upcoming OTP 24 with the JIT enabled, start the runtime system like this: "erl +asmdump" The generated assembly code for all loaded modules will be listed in text files with the extension *.asm.

/Björn
--
Björn Gustavsson, Erlang/OTP, Ericsson AB
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.