Skip to content

Commit 3b34eaa

Browse files
committed
Do not block module process for loading
1 parent aa51b1c commit 3b34eaa

File tree

2 files changed

+12
-33
lines changed

2 files changed

+12
-33
lines changed

lib/elixir/lib/kernel/parallel_compiler.ex

+6-18
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,10 @@ defmodule Kernel.ParallelCompiler do
422422
:erlang.put(:elixir_compiler_file, file)
423423

424424
try do
425-
if output == :require do
426-
require_file(file, parent)
427-
else
428-
compile_file(file, dest, parent)
425+
case output do
426+
{:compile, _} -> compile_file(file, dest, false, parent)
427+
:compile -> compile_file(file, dest, true, parent)
428+
:require -> require_file(file, parent)
429429
end
430430
catch
431431
kind, reason ->
@@ -530,9 +530,9 @@ defmodule Kernel.ParallelCompiler do
530530
wait_for_messages([], spawned, waiting, files, result, warnings, errors, state)
531531
end
532532

533-
defp compile_file(file, path, parent) do
533+
defp compile_file(file, path, force_load?, parent) do
534534
:erlang.process_flag(:error_handler, Kernel.ErrorHandler)
535-
:erlang.put(:elixir_compiler_dest, path)
535+
:erlang.put(:elixir_compiler_dest, {path, force_load?})
536536
:elixir_compiler.file(file, &each_file(&1, &2, parent))
537537
end
538538

@@ -633,18 +633,6 @@ defmodule Kernel.ParallelCompiler do
633633
state
634634
)
635635

636-
{:load_module?, child, ref, module} ->
637-
# If compiling files to disk, we only load the module
638-
# if other modules are waiting for it.
639-
load? =
640-
case state.output do
641-
{:compile, _} -> match?(%{{:module, ^module} => [_ | _]}, result)
642-
_ -> true
643-
end
644-
645-
send(child, {ref, load?})
646-
spawn_workers(queue, spawned, waiting, files, result, warnings, errors, state)
647-
648636
{{:module_loaded, module}, _ref, _type, _pid, _reason} ->
649637
result =
650638
Map.update!(result, {:module, module}, fn {binary, _loader} -> {binary, true} end)

lib/elixir/src/elixir_module.erl

+6-15
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ compile(Meta, Module, ModuleAsCharlist, Block, Vars, Prune, E) ->
155155
put_compiler_modules([Module | CompilerModules]),
156156
{Result, ModuleE, CallbackE} = eval_form(Line, Module, DataBag, Block, Vars, Prune, E),
157157
CheckerInfo = checker_info(),
158-
BeamLocation = beam_location(ModuleAsCharlist),
158+
{BeamLocation, Forceload} = beam_location(ModuleAsCharlist),
159159

160160
{Binary, PersistedAttributes, Autoload} =
161161
elixir_erl_compiler:spawn(fun() ->
@@ -215,7 +215,7 @@ compile(Meta, Module, ModuleAsCharlist, Block, Vars, Prune, E) ->
215215

216216
compile_error_if_tainted(DataSet, E),
217217
Binary = elixir_erl:compile(ModuleMap),
218-
Autoload = proplists:get_value(autoload, CompileOpts, false) or load_module(Module),
218+
Autoload = Forceload or proplists:get_value(autoload, CompileOpts, false),
219219
spawn_parallel_checker(CheckerInfo, Module, ModuleMap),
220220
{Binary, PersistedAttributes, Autoload}
221221
end),
@@ -544,10 +544,11 @@ bag_lookup_element(Table, Name, Pos) ->
544544

545545
beam_location(ModuleAsCharlist) ->
546546
case get(elixir_compiler_dest) of
547-
Dest when is_binary(Dest) ->
548-
filename:join(elixir_utils:characters_to_list(Dest), ModuleAsCharlist ++ ".beam");
547+
{Dest, Forceload} when is_binary(Dest) ->
548+
{filename:join(elixir_utils:characters_to_list(Dest), ModuleAsCharlist ++ ".beam"),
549+
Forceload};
549550
_ ->
550-
""
551+
{"", true}
551552
end.
552553

553554
%% Integration with elixir_compiler that makes the module available
@@ -585,16 +586,6 @@ make_module_available(Module, Binary, Loaded) ->
585586
receive {Ref, ack} -> ok end
586587
end.
587588

588-
load_module(Module) ->
589-
case get(elixir_compiler_info) of
590-
undefined ->
591-
true;
592-
{PID, _} ->
593-
Ref = make_ref(),
594-
PID ! {'load_module?', self(), Ref, Module},
595-
receive {Ref, Boolean} -> Boolean end
596-
end.
597-
598589
%% Error handling and helpers.
599590

600591
%% We've reached the elixir_module or eval internals, skip it with the rest

0 commit comments

Comments
 (0)