summaryrefslogtreecommitdiff
path: root/lib/elixir/lib/module/parallel_checker.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/elixir/lib/module/parallel_checker.ex')
-rw-r--r--lib/elixir/lib/module/parallel_checker.ex60
1 files changed, 19 insertions, 41 deletions
diff --git a/lib/elixir/lib/module/parallel_checker.ex b/lib/elixir/lib/module/parallel_checker.ex
index ca737457f..a16bf106a 100644
--- a/lib/elixir/lib/module/parallel_checker.ex
+++ b/lib/elixir/lib/module/parallel_checker.ex
@@ -10,8 +10,7 @@ defmodule Module.ParallelChecker do
the modules and adds the ExCk chunk to the binaries. Returns the updated
binaries and a list of warnings from the verification.
"""
- @spec verify([{%{}, binary()}], [{module(), binary()}], pos_integer()) ::
- {[{module(), binary()}], [warning()]}
+ @spec verify([{map(), binary()}], [{module(), binary()}], pos_integer()) :: [warning()]
def verify(compiled_modules, runtime_binaries, schedulers \\ nil) do
compiled_maps = Enum.map(compiled_modules, fn {map, _binary} -> {map.module, map} end)
check_modules = compiled_maps ++ runtime_binaries
@@ -21,36 +20,20 @@ defmodule Module.ParallelChecker do
preload_cache(get_ets(server), check_modules)
start(server)
- compiled_binaries = Enum.map(compiled_modules, fn {map, binary} -> {map.module, binary} end)
- old_binaries = Map.new(compiled_binaries ++ runtime_binaries)
- collect_results(old_binaries, [], [])
+ collect_results(length(check_modules), [])
end
- defp collect_results(old_binaries, binaries, warnings) when map_size(old_binaries) == 0 do
- {binaries, warnings}
+ defp collect_results(0, warnings) do
+ warnings
end
- defp collect_results(old_binaries, binaries, warnings) do
+ defp collect_results(count, warnings) do
receive do
- {__MODULE__, module, chunk, new_warnings} ->
- {binary, old_binaries} = Map.pop(old_binaries, module)
- binaries = [{module, add_chunk(chunk, binary)} | binaries]
-
- warnings = new_warnings ++ warnings
- collect_results(old_binaries, binaries, warnings)
+ {__MODULE__, _module, new_warnings} ->
+ collect_results(count - 1, new_warnings ++ warnings)
end
end
- defp add_chunk(nil, binary) do
- binary
- end
-
- defp add_chunk(chunk, binary) do
- {:ok, _module, chunks} = :beam_lib.all_chunks(binary)
- {:ok, binary} = :beam_lib.build_module([chunk | :lists.keydelete('ExCk', 1, chunks)])
- binary
- end
-
@doc """
Preloads a module into the cache. Call this function before any other
cache lookups for the module.
@@ -98,21 +81,6 @@ defmodule Module.ParallelChecker do
|> Enum.sort()
end
- @doc """
- Collects all exported functions and macros from the module definition ASTs.
- """
- @spec definitions_to_exports([{atom(), arity(), term(), term()}]) ::
- [{{atom(), arity()}, kind()}]
- def definitions_to_exports(definitions) do
- Enum.flat_map(definitions, fn {function, kind, _meta, _clauses} ->
- if kind in [:def, :defmacro] do
- [{function, kind}]
- else
- []
- end
- end)
- end
-
def init([modules, send_results, schedulers]) do
ets = :ets.new(:checker_cache, [:set, :public, {:read_concurrency, true}])
@@ -208,8 +176,8 @@ defmodule Module.ParallelChecker do
send_results_pid = state.send_results
spawn_link(fn ->
- {chunk, warnings} = Module.Checker.verify(verify, {parent, ets})
- send(send_results_pid, {__MODULE__, module, chunk, warnings})
+ warnings = Module.Checker.verify(verify, {parent, ets})
+ send(send_results_pid, {__MODULE__, module, warnings})
send(parent, {__MODULE__, :done})
end)
@@ -299,4 +267,14 @@ defmodule Module.ParallelChecker do
:ets.insert(ets, {{:all_exports, module}, exports})
:ets.insert(ets, {{:cached, module}, true})
end
+
+ defp definitions_to_exports(definitions) do
+ Enum.flat_map(definitions, fn {function, kind, _meta, _clauses} ->
+ if kind in [:def, :defmacro] do
+ [{function, kind}]
+ else
+ []
+ end
+ end)
+ end
end