Skip to content

Commit 5467b4e

Browse files
committed
Remove TODOs related to Erlang/OTP 22+
1 parent 7aec544 commit 5467b4e

File tree

7 files changed

+17
-74
lines changed

7 files changed

+17
-74
lines changed

lib/elixir/src/elixir.hrl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,3 @@
3030
warn_on_unnecessary_quotes=true,
3131
warnings=[]
3232
}).
33-
34-
%% TODO: Remove this once we support Erlang/OTP 22+ exclusively.
35-
%% See https://github.com/erlang/otp/pull/1972
36-
-if(?OTP_RELEASE >= 22).
37-
-define(NO_SPAWN_COMPILER_PROCESS, no_spawn_compiler_process).
38-
-else.
39-
-define(NO_SPAWN_COMPILER_PROCESS, dialyzer, no_spawn_compiler_process).
40-
-endif.

lib/elixir/src/elixir_erl.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ debug_info(core_v1, _Module, {elixir_v1, Map, Specs}, Opts) ->
2323
%% warnings nor the other functionality provided there.
2424
case elixir_erl_compiler:erl_to_core(Prefix ++ Specs ++ Forms, AllOpts) of
2525
{ok, CoreForms, _} ->
26-
try compile:noenv_forms(CoreForms, [?NO_SPAWN_COMPILER_PROCESS, from_core, core, return | AllOpts]) of
26+
try compile:noenv_forms(CoreForms, [no_spawn_compiler_process, from_core, core, return | AllOpts]) of
2727
{ok, _, Core, _} -> {ok, Core};
2828
_What -> {error, failed_conversion}
2929
catch

lib/elixir/src/elixir_erl_compiler.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ erl_to_core(Forms, Opts) ->
3636
[] ->
3737
v3_core:module(Forms, Opts);
3838
_ ->
39-
case compile:noenv_forms(Forms, [?NO_SPAWN_COMPILER_PROCESS, to_core0, return, no_auto_import | Opts]) of
39+
case compile:noenv_forms(Forms, [no_spawn_compiler_process, to_core0, return, no_auto_import | Opts]) of
4040
{ok, _Module, Core, Warnings} -> {ok, Core, Warnings};
4141
{error, Errors, Warnings} -> {error, Errors, Warnings}
4242
end
@@ -48,7 +48,7 @@ compile(Forms, File, Opts) when is_list(Forms), is_list(Opts), is_binary(File) -
4848
case erl_to_core(Forms, Opts) of
4949
{ok, CoreForms, CoreWarnings} ->
5050
format_warnings(Opts, CoreWarnings),
51-
CompileOpts = [?NO_SPAWN_COMPILER_PROCESS, from_core, no_core_prepare,
51+
CompileOpts = [no_spawn_compiler_process, from_core, no_core_prepare,
5252
no_auto_import, return, {source, Source} | Opts],
5353

5454
case compile:noenv_forms(CoreForms, CompileOpts) of

lib/logger/lib/logger/app.ex

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ defmodule Logger.App do
99
def start(_type, _args) do
1010
start_options = Application.get_env(:logger, :start_options)
1111
otp_reports? = Application.fetch_env!(:logger, :handle_otp_reports)
12-
config = Logger.Counter.new()
12+
counter = :counters.new(1, [:atomics])
1313

1414
children = [
1515
%{
1616
id: :gen_event,
1717
start: {:gen_event, :start_link, [{:local, Logger}, start_options]},
1818
modules: :dynamic
1919
},
20-
{Logger.Watcher, {Logger.Config, config}},
20+
{Logger.Watcher, {Logger.Config, counter}},
2121
Logger.BackendSupervisor
2222
]
2323

2424
case Supervisor.start_link(children, strategy: :rest_for_one, name: Logger.Supervisor) do
2525
{:ok, sup} ->
26-
primary_config = add_elixir_handler(otp_reports?, config)
26+
primary_config = add_elixir_handler(otp_reports?, counter)
2727

2828
default_handlers =
2929
if otp_reports? do
@@ -33,10 +33,9 @@ defmodule Logger.App do
3333
end
3434

3535
handlers = [{:primary, primary_config} | default_handlers]
36-
{:ok, sup, {config, handlers}}
36+
{:ok, sup, handlers}
3737

3838
{:error, _} = error ->
39-
Logger.Counter.delete(config)
4039
error
4140
end
4241
end
@@ -47,12 +46,10 @@ defmodule Logger.App do
4746
end
4847

4948
@doc false
50-
def stop({config, handlers}) do
49+
def stop(handlers) do
5150
_ = :logger.remove_handler(Logger)
5251
_ = :logger.remove_primary_filter(:process_disabled)
53-
5452
add_handlers(handlers)
55-
Logger.Counter.delete(config)
5653

5754
:logger.add_primary_filter(
5855
:silence_logger_exit,

lib/logger/lib/logger/config.ex

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ defmodule Logger.Config do
55
@name __MODULE__
66
@update_counter_message {__MODULE__, :update_counter}
77

8-
alias Logger.Counter
9-
108
def configure(options) do
119
:gen_event.call(Logger, @name, {:configure, options})
1210
end
@@ -76,6 +74,8 @@ defmodule Logger.Config do
7674
{:ok, state}
7775
end
7876

77+
@counter_pos 1
78+
7979
defp update_counter({counter, log, discard_threshold, discard_period}, periodic_check?) do
8080
# If length is more than the total, it means the counter is behind,
8181
# due to non-log messages, so we need to increase the counter.
@@ -88,9 +88,9 @@ defmodule Logger.Config do
8888
# deliver the message yet. Those bumps will be lost. At the same time,
8989
# we are careful to read the counter first here, so if the counter is
9090
# bumped after we read from it, those bumps won't be lost.
91-
total = Counter.read(counter)
91+
total = :counters.get(counter, @counter_pos)
9292
{:message_queue_len, length} = Process.info(self(), :message_queue_len)
93-
Counter.add(counter, length - total)
93+
:counters.add(counter, @counter_pos, length - total)
9494

9595
# In case we are logging but we reached the threshold, we log that we
9696
# started discarding messages. This can only be reverted by the periodic
@@ -128,7 +128,6 @@ defmodule Logger.Config do
128128
{:ok, %{config: data}} = :logger.get_handler_config(Logger)
129129
translators = fun.(data.translators)
130130
Application.put_env(:logger, :translators, translators)
131-
# TODO: Use update_handler_config on Erlang/OTP 22+.
132-
:ok = :logger.set_handler_config(Logger, :config, %{data | translators: translators})
131+
:ok = :logger.update_handler_config(Logger, :config, translators: translators)
133132
end
134133
end

lib/logger/lib/logger/counter.ex

Lines changed: 0 additions & 44 deletions
This file was deleted.

lib/logger/lib/logger/handler.ex

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
defmodule Logger.Handler do
22
@moduledoc false
3-
alias Logger.Counter
43

54
@internal_keys [:counter]
65

@@ -28,9 +27,6 @@ defmodule Logger.Handler do
2827
{:ok, update_in(config.config, &Map.merge(default_config(), &1))}
2928
end
3029

31-
# TODO: Remove this once we support Erlang/OTP 22+ exclusively.
32-
def changing_config(current, new), do: changing_config(:set, current, new)
33-
3430
def changing_config(
3531
op,
3632
%{config: %{counter: counter} = old_data} = old_config,
@@ -169,13 +165,16 @@ defmodule Logger.Handler do
169165
defp truncate(data, n) when is_binary(data), do: Logger.Utils.truncate(data, n)
170166
defp truncate(data, n), do: Logger.Utils.truncate(to_string(data), n)
171167

168+
@counter_pos 1
169+
172170
defp threshold(config) do
173171
%{
174172
counter: counter,
175173
thresholds: {sync, discard}
176174
} = config
177175

178-
value = Counter.bump(counter)
176+
:counters.add(counter, @counter_pos, 1)
177+
value = :counters.get(counter, @counter_pos)
179178

180179
cond do
181180
value >= discard -> :discard

0 commit comments

Comments
 (0)