Skip to content

Commit 6e455ea

Browse files
committed
More fixes
1 parent f7d8b29 commit 6e455ea

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

lib/elixir/lib/kernel/parallel_compiler.ex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ defmodule Kernel.ParallelCompiler do
139139
* `{:runtime, modules, warnings}` - to stop compilation and verify the list
140140
of modules because dependent modules have changed
141141
142+
* `:after_persistence` - ...
143+
142144
* `:long_compilation_threshold` - the timeout (in seconds) to check for modules
143145
taking too long to compile. For each file that exceeds the threshold, the
144146
`:each_long_compilation` callback is invoked. From Elixir v1.11, only the time
@@ -258,13 +260,6 @@ defmodule Kernel.ParallelCompiler do
258260
{status, modules_or_errors, info} =
259261
try do
260262
spawn_workers(schedulers, cache, files, output, options)
261-
else
262-
{:ok, outcome, info} ->
263-
beam_timestamp = Keyword.get(options, :beam_timestamp)
264-
{:ok, write_module_binaries(outcome, output, beam_timestamp), info}
265-
266-
{:error, errors, info} ->
267-
{:error, errors, info}
268263
after
269264
Module.ParallelChecker.stop(cache)
270265
end
@@ -288,7 +283,9 @@ defmodule Kernel.ParallelCompiler do
288283

289284
{outcome, state} =
290285
spawn_workers(files, %{}, %{}, [], %{}, [], [], %{
286+
beam_timestamp: Keyword.get(options, :beam_timestamp),
291287
dest: Keyword.get(options, :dest),
288+
after_persistence: Keyword.get(options, :after_persistence, fn -> :ok end),
292289
each_cycle: Keyword.get(options, :each_cycle, fn -> {:runtime, [], []} end),
293290
each_file: Keyword.get(options, :each_file, fn _, _ -> :ok end) |> each_file(),
294291
each_long_compilation: Keyword.get(options, :each_long_compilation, fn _file -> :ok end),
@@ -345,9 +342,11 @@ defmodule Kernel.ParallelCompiler do
345342
## Verification
346343

347344
defp verify_modules(result, compile_warnings, dependent_modules, state) do
345+
modules = write_module_binaries(result, state.output, state.beam_timestamp)
346+
_ = state.after_persistence.()
348347
runtime_warnings = maybe_check_modules(result, dependent_modules, state)
349348
info = %{compile_warnings: Enum.reverse(compile_warnings), runtime_warnings: runtime_warnings}
350-
{{:ok, result, info}, state}
349+
{{:ok, modules, info}, state}
351350
end
352351

353352
defp maybe_check_modules(result, runtime_modules, state) do

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,8 +1026,11 @@ defmodule Mix.Compilers.Elixir do
10261026
pid =
10271027
spawn_link(fn ->
10281028
compile_opts = [
1029+
after_persistence: fn ->
1030+
compiler_call(parent, ref, {:after_persistence, opts})
1031+
end,
10291032
each_cycle: fn ->
1030-
compiler_call(parent, ref, {:each_cycle, stale_modules, dest, timestamp, opts})
1033+
compiler_call(parent, ref, {:each_cycle, stale_modules, dest, timestamp})
10311034
end,
10321035
each_file: fn file, lexical ->
10331036
compiler_call(parent, ref, {:each_file, file, lexical, verbose})
@@ -1063,8 +1066,13 @@ defmodule Mix.Compilers.Elixir do
10631066

10641067
defp compiler_loop(ref, pid, state, cwd) do
10651068
receive do
1066-
{^ref, {:each_cycle, stale_modules, dest, timestamp, opts}} ->
1067-
{response, state} = each_cycle(stale_modules, dest, timestamp, state, opts)
1069+
{^ref, {:after_persistence, opts}} ->
1070+
{response, state} = after_persistence(state, opts)
1071+
send(pid, {ref, response})
1072+
compiler_loop(ref, pid, state, cwd)
1073+
1074+
{^ref, {:each_cycle, stale_modules, dest, timestamp}} ->
1075+
{response, state} = each_cycle(stale_modules, dest, timestamp, state)
10681076
send(pid, {ref, response})
10691077
compiler_loop(ref, pid, state, cwd)
10701078

@@ -1092,7 +1100,17 @@ defmodule Mix.Compilers.Elixir do
10921100
end
10931101
end
10941102

1095-
defp each_cycle(stale_modules, compile_path, timestamp, state, opts) do
1103+
defp after_persistence(state, opts) do
1104+
{modules, exports, sources, changed, pending_modules, stale_exports, consolidation} = state
1105+
1106+
state =
1107+
{modules, exports, sources, changed, pending_modules, stale_exports,
1108+
maybe_consolidate(consolidation, modules, opts)}
1109+
1110+
{:ok, state}
1111+
end
1112+
1113+
defp each_cycle(stale_modules, compile_path, timestamp, state) do
10961114
{modules, _exports, sources, changed, pending_modules, stale_exports, consolidation} = state
10971115

10981116
{pending_modules, exports, changed} =
@@ -1136,8 +1154,7 @@ defmodule Mix.Compilers.Elixir do
11361154
runtime_paths =
11371155
Enum.map(runtime_modules, &{&1, Path.join(compile_path, Atom.to_string(&1) <> ".beam")})
11381156

1139-
protocols_and_impls = maybe_consolidate(consolidation, modules, opts)
1140-
state = {modules, exports, sources, [], pending_modules, stale_exports, protocols_and_impls}
1157+
state = {modules, exports, sources, [], pending_modules, stale_exports, consolidation}
11411158
{{:runtime, runtime_paths, []}, state}
11421159
else
11431160
Mix.Utils.compiling_n(length(changed), :ex)

0 commit comments

Comments
 (0)