Skip to content

Commit 2a1d3d6

Browse files
author
José Valim
committed
Keep the full list of modules being defined
1 parent 86e221f commit 2a1d3d6

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

lib/elixir/lib/kernel/error_handler.ex

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,11 @@ defmodule Kernel.ErrorHandler do
2727
def ensure_compiled(module, kind) do
2828
parent = :erlang.get(:elixir_compiler_pid)
2929
ref = :erlang.make_ref
30-
send parent, {:waiting, kind, self(), ref, module, current_module()}
30+
send parent, {:waiting, kind, self(), ref, module, :elixir_module.compiler_modules()}
3131
:erlang.garbage_collect(self)
3232
receive do
3333
{^ref, :found} -> true
3434
{^ref, :not_found} -> false
3535
end
3636
end
37-
38-
defp current_module do
39-
case :erlang.get(:elixir_compiler_module) do
40-
:undefined -> nil
41-
other -> other
42-
end
43-
end
4437
end

lib/elixir/lib/kernel/parallel_compiler.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ defmodule Kernel.ParallelCompiler do
137137
# Queued x, waiting for x: POSSIBLE ERROR! Release processes so we get the failures
138138
defp spawn_compilers(%{entries: [], waiting: waiting, queued: queued} = state) when length(waiting) == length(queued) do
139139
entries = for {pid, _, _, _} <- queued,
140-
waiting_on_is_not_being_defined?(waiting, pid),
140+
not waiting_on_is_being_defined?(waiting, pid),
141141
do: {pid, :not_found}
142142

143143
case entries do
@@ -151,9 +151,9 @@ defmodule Kernel.ParallelCompiler do
151151
wait_for_messages(state)
152152
end
153153

154-
defp waiting_on_is_not_being_defined?(waiting, pid) do
154+
defp waiting_on_is_being_defined?(waiting, pid) do
155155
{_kind, ^pid, _, on, _defining} = List.keyfind(waiting, pid, 1)
156-
List.keyfind(waiting, on, 4) == nil
156+
Enum.any?(waiting, fn {_, _, _, _, defining} -> on in defining end)
157157
end
158158

159159
# Wait for messages from child processes

lib/elixir/src/elixir_module.erl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-module(elixir_module).
22
-export([data_table/1, defs_table/1, is_open/1, get_attribute/2, delete_doc/6,
3-
compile/4, expand_callback/6, add_beam_chunk/3, format_error/1]).
3+
compile/4, expand_callback/6, add_beam_chunk/3, format_error/1,
4+
compiler_modules/0]).
45
-include("elixir.hrl").
56

67
-define(acc_attr, {elixir, acc_attributes}).
@@ -9,6 +10,19 @@
910
-define(overridable_attr, {elixir, overridable}).
1011
-define(location_attr, {elixir, location}).
1112

13+
%% Stores modules currently being defined by the compiler
14+
15+
compiler_modules() ->
16+
case erlang:get(elixir_compiler_modules) of
17+
undefined -> [];
18+
M when is_list(M) -> M
19+
end.
20+
21+
put_compiler_modules([]) ->
22+
erlang:erase(elixir_compiler_modules);
23+
put_compiler_modules(M) when is_list(M) ->
24+
erlang:put(elixir_compiler_modules, M).
25+
1226
%% TABLE METHODS
1327

1428
data_table(Module) ->
@@ -59,11 +73,12 @@ do_compile(Line, Module, Block, Vars, E) ->
5973
File = ?m(E, file),
6074
check_module_availability(Line, File, Module),
6175

76+
CompilerModules = compiler_modules(),
6277
Docs = elixir_compiler:get_opt(docs),
6378
{Data, Defs, Ref} = build(Line, File, Module, Docs, ?m(E, lexical_tracker)),
6479

6580
try
66-
erlang:put(elixir_compiler_module, Module),
81+
put_compiler_modules([Module|CompilerModules]),
6782
{Result, NE} = eval_form(Line, Module, Data, Block, Vars, E),
6883

6984
_ = case ets:lookup(Data, 'on_load') of
@@ -108,7 +123,7 @@ do_compile(Line, Module, Block, Vars, E) ->
108123
erlang:raise(error, undef, Stack)
109124
end
110125
after
111-
erlang:erase(elixir_compiler_module),
126+
put_compiler_modules(CompilerModules),
112127
elixir_locals:cleanup(Module),
113128
ets:delete(Data),
114129
ets:delete(Defs),

0 commit comments

Comments
 (0)