Skip to content

Commit

Permalink
Move behaviour warnings to parallel checker
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Aug 29, 2022
1 parent 06b09e8 commit 0040270
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
11 changes: 1 addition & 10 deletions lib/elixir/lib/module.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1802,16 +1802,7 @@ defmodule Module do
defp args_count([], total, defaults), do: {total, defaults}

@doc false
def check_derive_behaviours_and_impls(env, set, bag, all_definitions) do
check_derive(env, set, bag)
behaviours = bag_lookup_element(bag, {:accumulate, :behaviour}, 2)
impls = bag_lookup_element(bag, :impls, 2)
Module.Behaviour.check_behaviours_and_impls(env, behaviours, impls, all_definitions)

:ok
end

defp check_derive(env, set, bag) do
def check_derive(env, set, bag) do
case bag_lookup_element(bag, {:accumulate, :derive}, 2) do
[] ->
:ok
Expand Down
10 changes: 1 addition & 9 deletions lib/elixir/lib/module/behaviour.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,7 @@ defmodule Module.Behaviour do

context = check_callbacks(context, all_definitions)

for warning <- context.warnings do
{__MODULE__, message, {file, line, _module}} = warning

message
|> format_warning()
|> Enum.join()
|> IO.warn(%{context.env | file: file, line: line})
end
context.warnings
end

defp context(env) do
Expand Down Expand Up @@ -64,7 +57,6 @@ defmodule Module.Behaviour do
warn(context, {:module_does_not_define_behaviour, context.env.module, behaviour})

true ->
:elixir_env.trace({:require, [from_macro: true], behaviour, []}, context.env)
optional_callbacks = behaviour_info(behaviour, :optional_callbacks)
callbacks = behaviour_info(behaviour, :callbacks)
Enum.reduce(callbacks, context, &add_callback(&2, &1, behaviour, optional_callbacks))
Expand Down
16 changes: 14 additions & 2 deletions lib/elixir/lib/module/parallel_checker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,29 @@ defmodule Module.ParallelChecker do
## Module checking

defp check_module(module_map, cache) do
%{module: module, file: file, compile_opts: compile_opts, definitions: definitions} =
module_map
%{
module: module,
file: file,
compile_opts: compile_opts,
definitions: definitions,
uses_behaviours: uses_behaviours,
impls: impls
} = module_map

no_warn_undefined =
compile_opts
|> extract_no_warn_undefined()
|> merge_compiler_no_warn_undefined()

env = Map.take(module_map, [:module, :file, :line])

behaviour_warnings =
Module.Behaviour.check_behaviours_and_impls(env, uses_behaviours, impls, definitions)

warnings =
module
|> Module.Types.warnings(file, definitions, no_warn_undefined, cache)
|> Kernel.++(behaviour_warnings)
|> group_warnings()
|> emit_warnings()

Expand Down
3 changes: 3 additions & 0 deletions lib/elixir/src/elixir_lexical.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ trace({alias, Meta, _Old, New, Opts}, #{lexical_tracker := Pid}) ->
trace({alias_expansion, _Meta, Lookup, _Result}, #{lexical_tracker := Pid}) ->
?tracker:alias_dispatch(Pid, Lookup),
ok;
trace({behaviour, _Meta, Module, _Opts}, #{lexical_tracker := Pid}) ->
?tracker:remote_dispatch(Pid, Module, runtime),
ok;
trace({require, Meta, Module, _Opts}, #{lexical_tracker := Pid}) ->
case lists:keyfind(from_macro, 1, Meta) of
{from_macro, true} -> ?tracker:remote_dispatch(Pid, Module, compile);
Expand Down
8 changes: 6 additions & 2 deletions lib/elixir/src/elixir_module.erl
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ compile(Line, Module, Block, Vars, E) ->
make_readonly(Module),

(not elixir_config:is_bootstrap()) andalso
'Elixir.Module':check_derive_behaviours_and_impls(E, DataSet, DataBag, AllDefinitions),
'Elixir.Module':check_derive(E, DataSet, DataBag),

RawCompileOpts = bag_lookup_element(DataBag, {accumulate, compile}, 2),
CompileOpts = validate_compile_opts(RawCompileOpts, AllDefinitions, Unreachable, File, Line),
AfterVerify = bag_lookup_element(DataBag, {accumulate, after_verify}, 2),
UsesBehaviours = bag_lookup_element(DataBag, {accumulate, behaviour}, 2),
Impls = bag_lookup_element(DataBag, impls, 2),

ModuleMap = #{
struct => get_struct(DataSet),
Expand All @@ -145,7 +147,9 @@ compile(Line, Module, Block, Vars, E) ->
after_verify => AfterVerify,
compile_opts => CompileOpts,
deprecated => get_deprecated(DataBag),
defines_behaviour => defines_behaviour(DataBag)
defines_behaviour => defines_behaviour(DataBag),
uses_behaviours => UsesBehaviours,
impls => Impls
},

Binary = elixir_erl:compile(ModuleMap),
Expand Down

0 comments on commit 0040270

Please sign in to comment.