Skip to content

Commit b18637f

Browse files
committed
Treat modules with --no-debug-info as uncached, closes #15159
Additionally make sure --debug-info is part of the cache key.
1 parent 7f3d95b commit b18637f

4 files changed

Lines changed: 60 additions & 7 deletions

File tree

lib/elixir/lib/module/parallel_checker.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ defmodule Module.ParallelChecker do
105105
{@elixir_checker_version, contents} <- :erlang.binary_to_term(checker) do
106106
{cache_chunk(table, module, contents), module_map_to_module_tuple(module_map)}
107107
else
108-
_ -> {:not_found, nil}
108+
_ -> {:uncached, nil}
109109
end
110110

111111
is_tuple(info) ->

lib/mix/lib/mix/tasks/compile.elixir.ex

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ defmodule Mix.Tasks.Compile.Elixir do
6363
* `--all-warnings` (`--no-all-warnings`) - prints all warnings, including previous compilations
6464
(default is true except on errors)
6565
* `--docs` (`--no-docs`) - attaches (or not) documentation to compiled modules
66-
* `--debug-info` (`--no-debug-info`) - attaches (or not) debug info to compiled modules
66+
* `--debug-info` (`--no-debug-info`) - attaches (or not) debug info to compiled modules.
67+
Passing this flag will force a full recompilation
6768
* `--force` - forces compilation regardless of modification times
6869
* `--ignore-module-conflict` - does not emit warnings if a module was previously defined
6970
* `--long-compilation-threshold N` - sets the "long compilation" threshold
@@ -73,9 +74,9 @@ defmodule Mix.Tasks.Compile.Elixir do
7374
* `--no-verification` - disables code verification, such as unused functions,
7475
deprecation warnings, and type checking. It must be used solely for debugging
7576
alongside `MIX_DEBUG=1`
76-
* `--no-check-cwd` - (since v1.19.2) Elixir stores absolute paths in .beam files, which means
77-
that relocating the project root triggers a full build. Pass this option if you don't want
78-
the current working directory to be checked
77+
* `--no-check-cwd` - (since v1.19.2) Elixir stores absolute paths in .beam files,
78+
which means that relocating the project root triggers a full build. Pass this option
79+
if you don't want the current working directory to be checked
7980
* `--purge-consolidation-path-if-stale PATH` - deletes and purges modules in the
8081
given protocol consolidation path if compilation is required
8182
* `--purge-compiler-modules` - automatically purge compilation modules
@@ -135,14 +136,17 @@ defmodule Mix.Tasks.Compile.Elixir do
135136

136137
manifest = manifest()
137138
base = xref_exclude_opts(project[:elixirc_options] || [], project)
138-
cache_key = {base, srcs, "--no-optional-deps" in args}
139139

140140
opts =
141141
base
142142
|> Keyword.merge(opts)
143143
|> tracers_opts(tracers)
144144
|> profile_opts()
145145

146+
# Optional dependencies and debug info affect how artifacts are generated
147+
cache_key =
148+
{base, srcs, "--no-optional-deps" in args, "--no-debug-info" in args}
149+
146150
opts =
147151
if "--no-protocol-consolidation" in args do
148152
# TODO: Deprecate me on Elixir v1.23

lib/mix/lib/mix/tasks/compile.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ defmodule Mix.Tasks.Compile do
7373
* `--no-listeners` - does not start Mix listeners
7474
* `--no-optional-deps` - does not compile or load optional deps. Useful for testing
7575
if a library still successfully compiles without optional dependencies (which is the
76-
default case with dependencies)
76+
default case with dependencies). Passing this flag will force a full recompilation
7777
* `--no-prune-code-paths` - do not prune code paths before compilation, this keeps
7878
the entirety of Erlang/OTP available when the project starts
7979
* `--no-protocol-consolidation` - skips protocol consolidation

lib/mix/test/mix/tasks/compile.elixir_test.exs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,55 @@ defmodule Mix.Tasks.Compile.ElixirTest do
322322
:elixir_config.put(:initial_dbg_callback, {Macro, :dbg, []})
323323
end
324324

325+
test "recompiles files on debug_info flag" do
326+
in_fixture("no_mixfile", fn ->
327+
Mix.Project.push(MixTest.Case.Sample)
328+
329+
File.write!("lib/a.ex", """
330+
defmodule DebugInfo.A do
331+
def run, do: :ok
332+
end
333+
""")
334+
335+
File.write!("lib/b.ex", """
336+
defmodule DebugInfo.B do
337+
def run, do: DebugInfo.A.run()
338+
end
339+
""")
340+
341+
File.write!("lib/c.ex", """
342+
defmodule DebugInfo.C do
343+
@compile_time_value DebugInfo.A.run()
344+
def compile_time_value, do: @compile_time_value
345+
def run, do: DebugInfo.B.run()
346+
end
347+
""")
348+
349+
assert Mix.Tasks.Compile.Elixir.run(["--verbose"]) == {:ok, []}
350+
assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
351+
assert_received {:mix_shell, :info, ["Compiled lib/b.ex"]}
352+
assert_received {:mix_shell, :info, ["Compiled lib/c.ex"]}
353+
354+
assert Mix.Tasks.Compile.Elixir.run(["--verbose", "--no-debug-info"]) == {:ok, []}
355+
assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
356+
assert_received {:mix_shell, :info, ["Compiled lib/b.ex"]}
357+
assert_received {:mix_shell, :info, ["Compiled lib/c.ex"]}
358+
359+
assert Mix.Tasks.Compile.Elixir.run(["--verbose", "--no-debug-info"]) == {:noop, []}
360+
361+
File.write!("lib/a.ex", """
362+
defmodule DebugInfo.A do
363+
def run, do: :error
364+
end
365+
""")
366+
367+
assert Mix.Tasks.Compile.Elixir.run(["--verbose", "--no-debug-info"]) == {:ok, []}
368+
assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
369+
refute_received {:mix_shell, :info, ["Compiled lib/b.ex"]}
370+
assert_received {:mix_shell, :info, ["Compiled lib/c.ex"]}
371+
end)
372+
end
373+
325374
test "recompiles files when config changes export dependencies" do
326375
in_fixture("no_mixfile", fn ->
327376
Mix.Project.push(MixTest.Case.Sample)

0 commit comments

Comments
 (0)