Skip to content

Commit

Permalink
Do not attempt to group module warnings with context
Browse files Browse the repository at this point in the history
Otherwise, the larger the context, the more expensive
grouping the warnings would get.

Closes #13742
  • Loading branch information
josevalim committed Jul 28, 2024
1 parent 3f0813e commit 438e13d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
34 changes: 25 additions & 9 deletions lib/elixir/lib/module/parallel_checker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -291,18 +291,34 @@ defmodule Module.ParallelChecker do
## Warning helpers

defp group_warnings(warnings) do
warnings
|> Enum.reduce(%{}, fn {module, warning, location}, acc ->
locations = MapSet.new([location])
Map.update(acc, {module, warning}, locations, &MapSet.put(&1, location))
end)
|> Enum.map(fn {{module, warning}, locations} -> {module, warning, Enum.sort(locations)} end)
|> Enum.sort()
{ungrouped, grouped} =
Enum.reduce(warnings, {[], %{}}, fn {module, warning, location}, {ungrouped, grouped} ->
%{message: _} = diagnostic = module.format_diagnostic(warning)

if Map.get(diagnostic, :group, false) do
locations = MapSet.new([location])

grouped =
Map.update(grouped, warning, {locations, diagnostic}, fn
{locations, diagnostic} -> {MapSet.put(locations, location), diagnostic}
end)

{ungrouped, grouped}
else
{[{[location], diagnostic} | ungrouped], grouped}
end
end)

grouped =
Enum.map(grouped, fn {_warning, {locations, diagnostic}} ->
{Enum.sort(locations), diagnostic}
end)

Enum.sort(ungrouped ++ grouped)
end

defp emit_warnings(warnings, log?) do
Enum.flat_map(warnings, fn {module, warning, locations} ->
%{message: _} = diagnostic = module.format_diagnostic(warning)
Enum.flat_map(warnings, fn {locations, diagnostic} ->
diagnostics = Enum.map(locations, &to_diagnostic(diagnostic, &1))
log? and print_diagnostics(diagnostics)
diagnostics
Expand Down
15 changes: 10 additions & 5 deletions lib/elixir/lib/module/types/of.ex
Original file line number Diff line number Diff line change
Expand Up @@ -700,14 +700,16 @@ defmodule Module.Types.Of do
" is undefined (module ",
inspect(module),
" is not available or is yet to be defined)"
])
]),
group: true
}
end

def format_diagnostic({:undefined_function, module, :__struct__, 0, _exports}) do
%{
message:
"struct #{inspect(module)} is undefined (there is such module but it does not define a struct)"
"struct #{inspect(module)} is undefined (there is such module but it does not define a struct)",
group: true
}
end

Expand All @@ -718,7 +720,8 @@ defmodule Module.Types.Of do
Exception.format_mfa(module, fun, arity),
" is undefined or private",
UndefinedFunctionError.hint_for_loaded_module(module, fun, arity, exports)
])
]),
group: true
}
end

Expand All @@ -729,7 +732,8 @@ defmodule Module.Types.Of do
Exception.format_mfa(module, fun, arity),
" is deprecated. ",
reason
])
]),
group: true
}
end

Expand All @@ -741,7 +745,8 @@ defmodule Module.Types.Of do
inspect(module),
" before invoking the macro ",
Exception.format_mfa(module, fun, arity)
])
]),
group: true
}
end

Expand Down

0 comments on commit 438e13d

Please sign in to comment.