Aetherus
I have a question in Part 1. Let me show my solution first:
defmodule Day21.Part1 do
def solve(), do: root()
@external_resource "#{__DIR__}/day21.txt"
for <<monkey::binary-4, ": ", expr::binary>> <- File.stream!(hd @external_resource),
monkey = String.to_atom(monkey) do
@compile {:inline, [{monkey, 0}]}
defp unquote(monkey)() do
unquote(Code.string_to_quoted!(expr))
end
end
end
I can get the result calling Day21.Part1.solve() (though it returns a float instead of an integer).
My question is, when I try disassembling the module (thanks to @isaac-rstor for teaching me this feature) and extract the instructions of solve/0,
Day21.Part1
|> :code.get_object_code()
|> elem(1)
|> :beam_disasm.file()
|> elem(5)
|> Enum.find(fn tuple ->
list = Tuple.to_list(tuple)
match?([:function, :solve | _], list)
end)
I get
{:function, :solve, 0, 789,
[
{:line, 3},
{:label, 788},
{:func_info, {:atom, Day21.Part1}, {:atom, :solve}, 0},
{:label, 789},
{:allocate, 0, 0},
{:line, 2},
{:call, 0, {Day21.Part1, :wvvv, 0}},
{:call, 0, {Day21.Part1, :whqc, 0}},
{:move, {:float, 83056452926300.0}, {:x, 0}},
{:deallocate, 0},
:return
]}
You can see the result in the :move instruction, that’s expected. The question is why there are still 2 :calls to the other functions? Why the instructions are not just
{:function, :solve, 0, 789,
[
{:line, 3},
{:label, 788},
{:func_info, {:atom, Day21.Part1}, {:atom, :solve}, 0},
{:label, 789},
{:line, 2},
{:move, {:float, 83056452926300.0}, {:x, 0}},
:return
]}
Trending in Challenges
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
bjorng
The Erlang compiler intentionally never removes function calls (unless the
inlineoption is used) to ensure that tracing of function calls will work predictably. That is, every call in source code should be present in the trace output.(Edited to mention the
inlineoption.)Aetherus
So, the 2
:calls are never executed in runtime?bjorng
Yes, they are executed, but their return values are ignored.
I now see that you used the
inlineoption. When inlining, the compiler will remove redundant function calls when calls are inlined. My guess why that didn’t happen is that the inliner gave up before it could inline all function calls in the module. It might be possible to force it to inline more if you also give the{inline_size, Size}option.