Skip to content

Commit a08de45

Browse files
committed
Clean up
1 parent 6c9602b commit a08de45

File tree

4 files changed

+58
-54
lines changed

4 files changed

+58
-54
lines changed

lib/elixir/lib/module/parallel_checker.ex

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,9 @@ defmodule Module.ParallelChecker do
4747
@doc """
4848
Spawns a process that runs the parallel checker.
4949
"""
50-
def spawn(pid_checker, module_map, log?, private, used, env) do
51-
%{module: module, definitions: definitions, file: file} = module_map
52-
53-
{signatures, unreachable} =
54-
Module.Types.infer(module, file, definitions, private, used, env)
55-
56-
module_map = %{module_map | signatures: signatures, unreachable: unreachable}
57-
58-
with {pid, checker} <- pid_checker do
59-
ets = :gen_server.call(checker, :ets, :infinity)
60-
inner_spawn(pid, checker, module, cache_from_module_map(ets, module_map), log?)
61-
end
62-
63-
module_map
50+
def spawn({pid, checker}, module, module_map, log?) do
51+
ets = :gen_server.call(checker, :ets, :infinity)
52+
inner_spawn(pid, checker, module, cache_from_module_map(ets, module_map), log?)
6453
end
6554

6655
defp inner_spawn(pid, checker, module, info, log?) do

lib/elixir/lib/module/types.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
defmodule Module.Types do
22
@moduledoc false
3-
43
alias Module.Types.{Descr, Expr, Pattern, Helpers}
5-
# TODO: Consider passing inferred types from infer into warnings
64

75
# These functions are not inferred because they are added/managed by the compiler
86
@no_infer [__protocol__: 1, behaviour_info: 1]

lib/elixir/src/elixir_module.erl

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,31 @@ compile(Meta, Module, ModuleAsCharlist, Block, Vars, Prune, E) ->
171171
NifsAttribute = lists:keyfind(nifs, 1, Attributes),
172172
validate_nifs_attribute(NifsAttribute, AllDefinitions, Line, E),
173173
elixir_import:ensure_no_local_conflict(Module, AllDefinitions, E),
174-
175174
make_readonly(Module),
176175

177176
(not elixir_config:is_bootstrap()) andalso
178177
'Elixir.Module':'__check_attributes__'(E, DataSet, DataBag),
179178

180-
RawCompileOpts = bag_lookup_element(DataBag, {accumulate, compile}, 2),
181-
CompileOpts = validate_compile_opts(RawCompileOpts, AllDefinitions, Line, E),
182-
Impls = bag_lookup_element(DataBag, impls, 2),
183-
184179
AfterVerify = bag_lookup_element(DataBag, {accumulate, after_verify}, 2),
185180
[elixir_env:trace({remote_function, [], VerifyMod, VerifyFun, 1}, CallbackE) ||
186181
{VerifyMod, VerifyFun} <- AfterVerify],
187182

188-
PartialModuleMap = #{
183+
%% Ensure there are no errors before we infer types
184+
compile_error_if_tainted(DataSet, E),
185+
186+
{Signatures, Unreachable} =
187+
case elixir_config:is_bootstrap() of
188+
true -> {#{}, []};
189+
false ->
190+
Used = bag_lookup_element(DataBag, macro_private_calls, 2),
191+
'Elixir.Module.Types':infer(Module, File, AllDefinitions, NewPrivate, Used, E)
192+
end,
193+
194+
RawCompileOpts = bag_lookup_element(DataBag, {accumulate, compile}, 2),
195+
CompileOpts = validate_compile_opts(RawCompileOpts, AllDefinitions, Unreachable, Line, E),
196+
Impls = bag_lookup_element(DataBag, impls, 2),
197+
198+
ModuleMap = #{
189199
struct => get_struct(DataSet),
190200
module => Module,
191201
anno => Anno,
@@ -198,17 +208,14 @@ compile(Meta, Module, ModuleAsCharlist, Block, Vars, Prune, E) ->
198208
deprecated => get_deprecated(DataBag),
199209
defines_behaviour => defines_behaviour(DataBag),
200210
impls => Impls,
201-
unreachable => [],
202-
signatures => #{}
211+
unreachable => Unreachable,
212+
signatures => Signatures
203213
},
204214

205-
%% Compute signatures only if the module is valid.
206-
compile_error_if_tainted(DataSet, E),
207-
ModuleMap = spawn_parallel_checker(DataBag, CheckerInfo, PartialModuleMap, NewPrivate, E),
208215
compile_error_if_tainted(DataSet, E),
209-
210216
Binary = elixir_erl:compile(ModuleMap),
211217
Autoload = proplists:get_value(autoload, CompileOpts, true),
218+
spawn_parallel_checker(CheckerInfo, Module, ModuleMap),
212219
{Binary, PersistedAttributes, Autoload}
213220
end),
214221

@@ -218,7 +225,7 @@ compile(Meta, Module, ModuleAsCharlist, Block, Vars, Prune, E) ->
218225
elixir_env:trace({on_module, Binary, none}, ModuleE),
219226
warn_unused_attributes(DataSet, DataBag, PersistedAttributes, E),
220227
make_module_available(Module, Binary),
221-
(CheckerInfo == nil) andalso
228+
(CheckerInfo == undefined) andalso
222229
[VerifyMod:VerifyFun(Module) ||
223230
{VerifyMod, VerifyFun} <- bag_lookup_element(DataBag, {accumulate, after_verify}, 2)],
224231
{module, Module, Binary, Result}
@@ -245,27 +252,41 @@ compile_error_if_tainted(DataSet, E) ->
245252
false -> ok
246253
end.
247254

248-
validate_compile_opts(Opts, Defs, Line, E) ->
249-
lists:flatmap(fun (Opt) -> validate_compile_opt(Opt, Defs, Line, E) end, Opts).
255+
validate_compile_opts(Opts, Defs, Unreachable, Line, E) ->
256+
lists:flatmap(fun (Opt) -> validate_compile_opt(Opt, Defs, Unreachable, Line, E) end, Opts).
250257

251258
%% TODO: Make this an error on v2.0
252-
validate_compile_opt({parse_transform, Module} = Opt, _Defs, Line, E) ->
259+
validate_compile_opt({parse_transform, Module} = Opt, _Defs, _Unreachable, Line, E) ->
253260
elixir_errors:file_warn([{line, Line}], E, ?MODULE, {parse_transform, Module}),
254261
[Opt];
255-
validate_compile_opt({inline, Inlines} = Opt, Defs, Line, E) ->
256-
[case lists:keyfind(Inline, 1, Defs) of
262+
validate_compile_opt({inline, Inlines}, Defs, Unreachable, Line, E) ->
263+
case validate_inlines(Inlines, Defs, Unreachable, []) of
264+
{ok, []} ->
265+
[];
266+
{ok, FilteredInlines} ->
267+
[{inline, FilteredInlines}];
268+
{error, Reason} ->
269+
elixir_errors:module_error([{line, Line}], E, ?MODULE, Reason),
270+
[]
271+
end;
272+
validate_compile_opt(Opt, Defs, Unreachable, Line, E) when is_list(Opt) ->
273+
validate_compile_opts(Opt, Defs, Unreachable, Line, E);
274+
validate_compile_opt(Opt, _Defs, _Unreachable, _Line, _E) ->
275+
[Opt].
276+
277+
validate_inlines([Inline | Inlines], Defs, Unreachable, Acc) ->
278+
case lists:keyfind(Inline, 1, Defs) of
257279
false ->
258-
elixir_errors:module_error([{line, Line}], E, ?MODULE, {undefined_function, {compile, inline}, Inline});
280+
{error, {undefined_function, {compile, inline}, Inline}};
259281
{_Def, Type, _Meta, _Clauses} when Type == defmacro; Type == defmacrop ->
260-
elixir_errors:module_error([{line, Line}], E, ?MODULE, {bad_macro, {compile, inline}, Inline});
282+
{error, {bad_macro, {compile, inline}, Inline}};
261283
_ ->
262-
ok
263-
end || Inline <- Inlines],
264-
[Opt];
265-
validate_compile_opt(Opt, Defs, Line, E) when is_list(Opt) ->
266-
validate_compile_opts(Opt, Defs, Line, E);
267-
validate_compile_opt(Opt, _Defs, _Line, _E) ->
268-
[Opt].
284+
case lists:member(Inline, Unreachable) of
285+
true -> validate_inlines(Inlines, Defs, Unreachable, Acc);
286+
false -> validate_inlines(Inlines, Defs, Unreachable, [Inline | Acc])
287+
end
288+
end;
289+
validate_inlines([], _Defs, _Unreachable, Acc) -> {ok, Acc}.
269290

270291
validate_on_load_attribute({on_load, Def}, Defs, Private, Line, E) ->
271292
case lists:keyfind(Def, 1, Defs) of
@@ -534,23 +555,19 @@ beam_location(ModuleAsCharlist) ->
534555

535556
checker_info() ->
536557
case get(elixir_checker_info) of
537-
undefined -> nil;
558+
undefined -> undefined;
538559
_ -> 'Elixir.Module.ParallelChecker':get()
539560
end.
540561

541-
spawn_parallel_checker(DataBag, CheckerInfo, ModuleMap, Private, E) ->
562+
spawn_parallel_checker(undefined, _Module, _ModuleMap) ->
563+
ok;
564+
spawn_parallel_checker(CheckerInfo, Module, ModuleMap) ->
542565
Log =
543566
case erlang:get(elixir_code_diagnostics) of
544567
{_, false} -> false;
545568
_ -> true
546569
end,
547-
548-
Used = bag_lookup_element(DataBag, macro_private_calls, 2),
549-
550-
case elixir_config:is_bootstrap() of
551-
true -> ModuleMap;
552-
false -> 'Elixir.Module.ParallelChecker':spawn(CheckerInfo, ModuleMap, Log, Private, Used, E)
553-
end.
570+
'Elixir.Module.ParallelChecker':spawn(CheckerInfo, Module, ModuleMap, Log).
554571

555572
make_module_available(Module, Binary) ->
556573
case get(elixir_module_binaries) of

lib/elixir/test/elixir/kernel/errors_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,8 @@ defmodule Kernel.ErrorsTest do
739739
)
740740

741741
assert_compile_error(
742-
["nofile:1: ", "undefined function foo/1 given to @compile :inline"],
743-
~c"defmodule Test do @compile {:inline, foo: 1}; defmacro foo(_) end"
742+
["nofile:1: ", "macro foo/1 given to @compile :inline"],
743+
~c"defmodule Test do @compile {:inline, foo: 1}; defmacro foo(_), do: :ok end"
744744
)
745745
end
746746

0 commit comments

Comments
 (0)