`line_coverage` compiler option in `-compile` attribute
Describe the bug
I don't seem to be able to enable line_coverage compiler option using -compile attribute. This is not consistent with compile documentation that says:
All options, except the include path ({i,Dir}), can also be given in the file with attribute -compile([Option,...]). Attribute -compile() is allowed after the function definitions.
Am I doing something wrong?
To Reproduce With OTP 27 or 27.1.1 erlc compiler, compile the following:
-module(test_executable_line).
-compile([line_coverage]).
-export([start/0]).
start() ->
ok = test_executable_line(),
0.
test_executable_line() ->
ModuleInfo = ?MODULE:module_info(),
CompileList = proplists_get_value(compile, ModuleInfo),
true = is_list(CompileList),
OptionsList = proplists_get_value(options, CompileList),
erlang:display({compile_options, OptionsList}),
erlang:display({emu_flavor, erlang:system_info(emu_flavor)}),
ok.
proplists_get_value(_Key, []) -> undefined;
proplists_get_value(Key, [{Key, Value} | _Tail]) -> Value;
proplists_get_value(Key, [_Pair | Tail]) -> proplists_get_value(Key, Tail).
Alternatively, replace line 2 with:
-compile(line_coverage).
line_coverage is never included in the options in the module info. Besides, compiling with -S shows that indeed executable_line opcode is not emitted.
Alternatively, compile with erlc +line_coverage and the option is in module info and executable_line opcode is emitted.
Expected behavior
I expect to be able to generate executable_line opcodes using -compile attribute.
Affected versions This is 27.0 and 27.1.1.
Additional context
I'm trying to implement and test executable_line opcode in AtomVM after watching @bjorng excellent and insightful talk at CodeBEAM Europe 2024 as I realized we are missing it.
Thanks for the bug report and your kind words about my talk. It was nice meeting you at the conference. I am impressed how the AtomVM is able to execute BEAM in such a small amount of memory.
The linked pull request fixes the bug. It will be included in Erlang/OTP 27.2.