Skip to content

Commit 887e218

Browse files
committed
Fix checker on missing debug info, closes #12140
1 parent 1c39141 commit 887e218

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

lib/elixir/lib/code.ex

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,12 +1334,16 @@ defmodule Code do
13341334
13351335
Available options are:
13361336
1337-
* `:docs` - when `true`, retain documentation in the compiled module.
1337+
* `:docs` - when `true`, retains documentation in the compiled module.
13381338
Defaults to `true`.
13391339
1340-
* `:debug_info` - when `true`, retain debug information in the compiled
1341-
module. This allows a developer to reconstruct the original source
1342-
code. Defaults to `true`.
1340+
* `:debug_info` - when `true`, retains debug information in the compiled
1341+
module. This enables static analysis tools as it allows developers to
1342+
partially reconstruct the original source code. Therefore, disabling
1343+
`:debug_info` is not recommended as it removes the ability of the
1344+
Elixir compiler and other tools to provide feedback. If you want to
1345+
remove the `:debug_info` while deploying, tools like `mix release`
1346+
already do such by default.
13431347
13441348
* `:ignore_already_consolidated` - when `true`, does not warn when a protocol
13451349
has already been consolidated and a new implementation is added. Defaults
@@ -1348,7 +1352,7 @@ defmodule Code do
13481352
* `:ignore_module_conflict` - when `true`, does not warn when a module has
13491353
already been defined. Defaults to `false`.
13501354
1351-
* `:relative_paths` - when `true`, use relative paths in quoted nodes,
1355+
* `:relative_paths` - when `true`, uses relative paths in quoted nodes,
13521356
warnings, and errors generated by the compiler. Note disabling this option
13531357
won't affect runtime warnings and errors. Defaults to `true`.
13541358

lib/elixir/lib/module.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,11 @@ defmodule Module do
532532
corresponding setting in `Code.get_compiler_option/1`
533533
534534
* `@compile {:debug_info, false}` - disables `:debug_info` regardless
535-
of the corresponding setting in `Code.get_compiler_option/1`
535+
of the corresponding setting in `Code.get_compiler_option/1`. Note
536+
disabling `:debug_info` is not recommended as it removes the ability
537+
of the Elixir compiler and other tools to static analyse the code.
538+
If you want to remove the `:debug_info` while deploying, tools like
539+
`mix release` already do such by default.
536540
537541
* `@compile {:inline, some_fun: 2, other_fun: 3}` - inlines the given
538542
name/arity pairs. Inlining is applied locally, calls from another

lib/elixir/lib/module/parallel_checker.ex

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,24 @@ defmodule Module.ParallelChecker do
6262
if is_map(info) do
6363
info
6464
else
65-
info |> File.read!() |> fetch_module_map!(module)
65+
info |> File.read!() |> maybe_module_map(module)
6666
end
6767

68-
cache_from_module_map(ets, module_map)
68+
module_map && cache_from_module_map(ets, module_map)
6969
send(checker, {ref, :cached})
7070

7171
receive do
7272
{^ref, :check} ->
7373
# Set the compiler info so we can collect warnings
7474
:erlang.put(:elixir_compiler_info, {pid, self()})
75-
warnings = check_module(module_map, {checker, ets})
75+
76+
warnings =
77+
if module_map do
78+
check_module(module_map, {checker, ets})
79+
else
80+
[]
81+
end
82+
7683
send(pid, {__MODULE__, module, warnings})
7784
send(checker, {__MODULE__, :done})
7885
end
@@ -357,21 +364,15 @@ defmodule Module.ParallelChecker do
357364
_ -> %{}
358365
end
359366

360-
defp fetch_module_map!(binary, module) when is_binary(binary) do
361-
{:ok, {_, [debug_info: chunk]}} = :beam_lib.chunks(binary, [:debug_info])
362-
{:debug_info_v1, backend, data} = chunk
363-
364-
case backend.debug_info(:elixir_v1, module, data, []) do
365-
{:ok, module_map} ->
366-
module_map
367-
368-
{:error, error} ->
369-
raise """
370-
could not load Elixir metadata for module #{inspect(module)}, \
371-
written in backend #{inspect(backend)}, due to reason: #{inspect(error)}
372-
373-
Please report this bug: https://github.com/elixir-lang/elixir/issues
374-
"""
367+
defp maybe_module_map(binary, module) when is_binary(binary) do
368+
# If a module was compiled without debug_info,
369+
# then there is no module_map for further verification.
370+
with {:ok, {_, [debug_info: chunk]}} <- :beam_lib.chunks(binary, [:debug_info]),
371+
{:debug_info_v1, backend, data} = chunk,
372+
{:ok, module_map} <- backend.debug_info(:elixir_v1, module, data, []) do
373+
module_map
374+
else
375+
_ -> nil
375376
end
376377
end
377378

0 commit comments

Comments
 (0)