Weird limit in number of function clauses when running on aarch64

I have some code that generates a few thousand function clauses via a macro that runs fine in most platforms but when trying to run it in Docker on an ARM mac it fails in a weird way.

Here’s a contrived example that reproduces the issue:

defmodule Test do
  Enum.each 1..4096, fn id ->
    def __id__(unquote(id)) do
      IO.puts("Executing clause for #{unquote(id)}")
    end
  end
end


Test.__id__(2)

If running on native Linux or Mac, this code runs fine regardless of the number of clauses generated but when running in an “aarch64 Linux” docker image, then the code compiles fine in every case but the call to Test.__id__(2) fails with a no function clause matching error when the number of clauses is bigger than 4096.

This is happening with Erlang/OTP 25 [erts-13.2] and Elixir 1.14.2.

It there something that I’m missing here or should I open a bug in the github repo?

Thanks!

1 Like

I think I see why, can you apply this commit and see if it fixes the problem?

2 Likes

Well @jhogberg, it seems like that is precisely the problem in this case!

I borrowed the erlang and elixir Dockerfiles and combined them into a single one to test this in GitHub - opsidao/erlang_clause_limit_but_on_arm: Small reproduction of erlang bug. I added a small, dirty, one liner to apply the patch using sed and the error stops happening.

What would be the next step here? Should I report it somewhere?

1 Like

No need, I’ll open a PR with the fix shortly and prepare it for release in the next patch. In the future you can report similar issues at Issues · erlang/otp · GitHub if you wish. :slight_smile:

Thanks for reporting it! :slight_smile:

3 Likes