Skip to content

Commit b912913

Browse files
committed
Allow verification to be disabled with MIX_DEBUG=1
1 parent 9913a77 commit b912913

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed

lib/elixir/lib/kernel/parallel_compiler.ex

+21-13
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ defmodule Kernel.ParallelCompiler do
162162
threshold, the `:each_long_verification` callback is invoked. Defaults to
163163
`10` seconds.
164164
165+
* `:verification` (since v1.19.0) - if code verification, such as unused functions,
166+
deprecation warnings, and type checking should run. Defaults to `true`.
167+
We recommend disabling it only for debugging purposes.
168+
165169
* `:profile` - if set to `:time` measure the compilation time of each compilation cycle
166170
and group pass checker
167171
@@ -310,7 +314,8 @@ defmodule Kernel.ParallelCompiler do
310314
timer_ref: timer_ref,
311315
long_compilation_threshold: threshold,
312316
schedulers: schedulers,
313-
checker: checker
317+
checker: checker,
318+
verification?: Keyword.get(options, :verification, true)
314319
})
315320

316321
Process.cancel_timer(state.timer_ref)
@@ -358,22 +363,25 @@ defmodule Kernel.ParallelCompiler do
358363
defp verify_modules(result, compile_warnings, dependent_modules, state) do
359364
modules = write_module_binaries(result, state.output, state.beam_timestamp)
360365
_ = state.after_compile.()
361-
runtime_warnings = maybe_check_modules(modules, dependent_modules, state)
366+
367+
runtime_warnings =
368+
if state.verification? do
369+
profile(
370+
state,
371+
fn ->
372+
num_modules = length(modules) + length(dependent_modules)
373+
"group pass check of #{num_modules} modules"
374+
end,
375+
fn -> Module.ParallelChecker.verify(state.checker, dependent_modules) end
376+
)
377+
else
378+
[]
379+
end
380+
362381
info = %{compile_warnings: Enum.reverse(compile_warnings), runtime_warnings: runtime_warnings}
363382
{{:ok, modules, info}, state}
364383
end
365384

366-
defp maybe_check_modules(compiled_modules, runtime_modules, state) do
367-
profile(
368-
state,
369-
fn ->
370-
num_modules = length(compiled_modules) + length(runtime_modules)
371-
"group pass check of #{num_modules} modules"
372-
end,
373-
fn -> Module.ParallelChecker.verify(state.checker, runtime_modules) end
374-
)
375-
end
376-
377385
defp profile_init(:time), do: {:time, System.monotonic_time(), 0}
378386
defp profile_init(nil), do: :none
379387

lib/mix/lib/mix/compilers/elixir.ex

+9-3
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,12 @@ defmodule Mix.Compilers.Elixir do
10041004
compilation_threshold = opts[:long_compilation_threshold] || 10
10051005
verification_threshold = opts[:long_verification_threshold] || 10
10061006
profile = opts[:profile]
1007-
verbose = opts[:verbose] || false
1007+
verbose = Keyword.get(opts, :verbose, false)
1008+
verification = Keyword.get(opts, :verification, true)
1009+
1010+
if not verification and not Mix.debug?() do
1011+
Mix.shell().error("--no-verification flag is only recommended with MIX_DEBUG=1")
1012+
end
10081013

10091014
pid =
10101015
spawn_link(fn ->
@@ -1035,9 +1040,10 @@ defmodule Mix.Compilers.Elixir do
10351040
end,
10361041
long_compilation_threshold: compilation_threshold,
10371042
long_verification_threshold: verification_threshold,
1038-
profile: profile,
10391043
beam_timestamp: timestamp,
1040-
return_diagnostics: true
1044+
return_diagnostics: true,
1045+
profile: profile,
1046+
verification: verification
10411047
]
10421048

10431049
response = Kernel.ParallelCompiler.compile_to_path(stale, dest, compile_opts)

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

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ defmodule Mix.Tasks.Compile.Elixir do
7070
(in seconds) to `N` (see the docs for `Kernel.ParallelCompiler.compile/2`)
7171
* `--long-verification-threshold N` - sets the "long verification" threshold
7272
(in seconds) to `N` (see the docs for `Kernel.ParallelCompiler.compile/2`)
73+
* `--no-verification` - disables code verification, such as unused functions,
74+
deprecation warnings, and type checking. It must be used alongside `MIX_DEBUG=1`
7375
* `--purge-consolidation-path-if-stale PATH` - deletes and purges modules in the
7476
given protocol consolidation path if compilation is required
7577
* `--profile` - if set to `time`, outputs timing information of compilation steps
@@ -106,6 +108,7 @@ defmodule Mix.Tasks.Compile.Elixir do
106108
purge_consolidation_path_if_stale: :string,
107109
profile: :string,
108110
all_warnings: :boolean,
111+
verification: :boolean,
109112
tracer: :keep
110113
]
111114

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

+10
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,16 @@ defmodule Mix.Tasks.Compile.ElixirTest do
16661666
assert output =~ "B.foo/0 is undefined or private"
16671667
assert output =~ "B.bar/0 is undefined or private"
16681668
assert output =~ "AFTER_VERIFY"
1669+
1670+
# But we can also disable verification if we want to
1671+
output =
1672+
capture_io(:stderr, fn ->
1673+
Mix.Tasks.Compile.Elixir.run(["--no-verification", "--force"])
1674+
end)
1675+
1676+
refute output =~ "B.foo/0 is undefined or private"
1677+
refute output =~ "B.bar/0 is undefined or private"
1678+
refute output =~ "AFTER_VERIFY"
16691679
end)
16701680
end
16711681

0 commit comments

Comments
 (0)