otp icon indicating copy to clipboard operation
otp copied to clipboard

Using 'inline_list_funcs' with lists:xxx

Open DominicGame opened this issue 2 years ago • 2 comments

Describe the bug lists:all(fun erlang:is_integer/1, Values) compile with inline_list_funcs

To Reproduce Warning: this clause cannot match because a previous clause always matches

Expected behavior no warning

Affected versions with 24.3.4 on WLS

Additional context see more in: https://erlangforums.com/t/using-inline-list-funcs-with-lists-xxx/1654

DominicGame avatar Jul 18 '22 12:07 DominicGame

I suspect something strange happens in an compiler internal pass. This will have to wait until our compiler people are back from their vacation.

I have only figured out that when using fun erlang:is_integer/1 the compiler manages to inline the function call and the loop becomes only 4 .beam assembly instructions. When using fun is_integer/1 the compiler writes a function precisely as for fun (X) -> is_integer end, a function that just calls the BIF is_integer/1, but the loop in this case calls the function and checks the return value so the loop becomes 10 .beam assembly instructions.

But why the faster code gets a warning is weird. I se no problem with the generated assembly code.

RaimoNiskanen avatar Jul 18 '22 16:07 RaimoNiskanen

Affected versions with 24.3.4 on WLS

For the record, same for 25.0.3 and 23.3 on Ubuntu.

Maria-12648430 avatar Jul 19 '22 04:07 Maria-12648430

The linked pull request resolves the issue. It will be included in OTP 25.1.

bjorng avatar Aug 23 '22 11:08 bjorng