You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The documentation for System Limits states that the maximum number of arguments for a fun is 255. This is true in the sense that the compiler allows literal funs with up to 255 arguments and rejects literal funs with more arguments. However, this is not the entire story.
The following example module, which has a function test/1 which returns a fun with 255 arguments, compiles:
On closer inspection, it turns out that variables that were defined outside but used inside of the fun ( Y in the example above) are passed as "hidden" arguments, and thereby count towards the maximum number of arguments.
To Reproduce
Compile the above module
Load the compiled module
Expected behavior
The above module should not compile, instead of compiling to something that can't be loaded. On OTP 27.0 (but not earlier or later), trying to load this module even resulted in a segmentation fault.
The documentation should be augmented to say that variables defined outside and used inside a fun count towards the limit.
Affected versions
All versions, as far as I can tell.
Additional context
The cleanest solution would be to let such variables not count towards the limit, in accordance with what the documentation states. However, given that this is a very unlikely edge case (maybe it could happen in generated code, I don't know), a compilation error and augmentation of the documentation is probably fine.
The text was updated successfully, but these errors were encountered:
Thanks for the report! Making environment variables not count has some tricky implications elsewhere, so for now I've opted for updating the documentation and making the compiler reject these funs in #9121.
I assume the OTP team has considered but rejected the option of passing the closure (tuple) as a single "extra" parameter, and let the callee deal with extracting whatever free variables it wants?
Yes, we’ve considered that with the added twist of passing the fun itself, so that named anonymous funs with environment can reuse the called fun instead of having to create a new one. It’s been in the backlog for years and I’m not sure when we’ll get around to it.
Describe the bug
The documentation for System Limits states that the maximum number of arguments for a
fun
is 255. This is true in the sense that the compiler allows literalfun
s with up to 255 arguments and rejects literalfun
s with more arguments. However, this is not the entire story.The following example module, which has a function
test/1
which returns afun
with 255 arguments, compiles:But it cannot be loaded:
On closer inspection, it turns out that variables that were defined outside but used inside of the
fun
(Y
in the example above) are passed as "hidden" arguments, and thereby count towards the maximum number of arguments.To Reproduce
Expected behavior
The above module should not compile, instead of compiling to something that can't be loaded. On OTP 27.0 (but not earlier or later), trying to load this module even resulted in a segmentation fault.
The documentation should be augmented to say that variables defined outside and used inside a
fun
count towards the limit.Affected versions
All versions, as far as I can tell.
Additional context
The cleanest solution would be to let such variables not count towards the limit, in accordance with what the documentation states. However, given that this is a very unlikely edge case (maybe it could happen in generated code, I don't know), a compilation error and augmentation of the documentation is probably fine.
The text was updated successfully, but these errors were encountered: