Skip to content

Commit 438e13d

Browse files
committed
Do not attempt to group module warnings with context
Otherwise, the larger the context, the more expensive grouping the warnings would get. Closes #13742
1 parent 3f0813e commit 438e13d

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

lib/elixir/lib/module/parallel_checker.ex

+25-9
Original file line numberDiff line numberDiff line change
@@ -291,18 +291,34 @@ defmodule Module.ParallelChecker do
291291
## Warning helpers
292292

293293
defp group_warnings(warnings) do
294-
warnings
295-
|> Enum.reduce(%{}, fn {module, warning, location}, acc ->
296-
locations = MapSet.new([location])
297-
Map.update(acc, {module, warning}, locations, &MapSet.put(&1, location))
298-
end)
299-
|> Enum.map(fn {{module, warning}, locations} -> {module, warning, Enum.sort(locations)} end)
300-
|> Enum.sort()
294+
{ungrouped, grouped} =
295+
Enum.reduce(warnings, {[], %{}}, fn {module, warning, location}, {ungrouped, grouped} ->
296+
%{message: _} = diagnostic = module.format_diagnostic(warning)
297+
298+
if Map.get(diagnostic, :group, false) do
299+
locations = MapSet.new([location])
300+
301+
grouped =
302+
Map.update(grouped, warning, {locations, diagnostic}, fn
303+
{locations, diagnostic} -> {MapSet.put(locations, location), diagnostic}
304+
end)
305+
306+
{ungrouped, grouped}
307+
else
308+
{[{[location], diagnostic} | ungrouped], grouped}
309+
end
310+
end)
311+
312+
grouped =
313+
Enum.map(grouped, fn {_warning, {locations, diagnostic}} ->
314+
{Enum.sort(locations), diagnostic}
315+
end)
316+
317+
Enum.sort(ungrouped ++ grouped)
301318
end
302319

303320
defp emit_warnings(warnings, log?) do
304-
Enum.flat_map(warnings, fn {module, warning, locations} ->
305-
%{message: _} = diagnostic = module.format_diagnostic(warning)
321+
Enum.flat_map(warnings, fn {locations, diagnostic} ->
306322
diagnostics = Enum.map(locations, &to_diagnostic(diagnostic, &1))
307323
log? and print_diagnostics(diagnostics)
308324
diagnostics

lib/elixir/lib/module/types/of.ex

+10-5
Original file line numberDiff line numberDiff line change
@@ -700,14 +700,16 @@ defmodule Module.Types.Of do
700700
" is undefined (module ",
701701
inspect(module),
702702
" is not available or is yet to be defined)"
703-
])
703+
]),
704+
group: true
704705
}
705706
end
706707

707708
def format_diagnostic({:undefined_function, module, :__struct__, 0, _exports}) do
708709
%{
709710
message:
710-
"struct #{inspect(module)} is undefined (there is such module but it does not define a struct)"
711+
"struct #{inspect(module)} is undefined (there is such module but it does not define a struct)",
712+
group: true
711713
}
712714
end
713715

@@ -718,7 +720,8 @@ defmodule Module.Types.Of do
718720
Exception.format_mfa(module, fun, arity),
719721
" is undefined or private",
720722
UndefinedFunctionError.hint_for_loaded_module(module, fun, arity, exports)
721-
])
723+
]),
724+
group: true
722725
}
723726
end
724727

@@ -729,7 +732,8 @@ defmodule Module.Types.Of do
729732
Exception.format_mfa(module, fun, arity),
730733
" is deprecated. ",
731734
reason
732-
])
735+
]),
736+
group: true
733737
}
734738
end
735739

@@ -741,7 +745,8 @@ defmodule Module.Types.Of do
741745
inspect(module),
742746
" before invoking the macro ",
743747
Exception.format_mfa(module, fun, arity)
744-
])
748+
]),
749+
group: true
745750
}
746751
end
747752

0 commit comments

Comments
 (0)