Skip to content

Commit b90fdf2

Browse files
authored
Update to elixir 1.19 (#1038)
* Start satisfying credo * Satisfy credo * Satisfy the compiler * Fix cp_r * Disable dialyzer opaque checks * Remove commented code * Apply reviewers suggestions * Improve comments
1 parent c96997c commit b90fdf2

32 files changed

Lines changed: 122 additions & 91 deletions

lib/membrane/children_spec.ex

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,9 @@ defmodule Membrane.ChildrenSpec do
452452
via_in(builder, :input)
453453
end
454454
|> Builder.finish_link(child_name)
455-
|> then(&%Builder{&1 | children: [child_spec | &1.children]})
455+
|> then(fn %Builder{} = builder ->
456+
%Builder{builder | children: [child_spec | builder.children]}
457+
end)
456458
end
457459

458460
@doc """
@@ -465,7 +467,9 @@ defmodule Membrane.ChildrenSpec do
465467
:ok = validate_pad_name(pad)
466468

467469
get_child({Membrane.Bin, :itself})
468-
|> then(&%Builder{&1 | status: :from_pad, from_pad: pad, from_pad_props: %{}})
470+
|> then(fn %Builder{} = builder ->
471+
%Builder{builder | status: :from_pad, from_pad: pad, from_pad_props: %{}}
472+
end)
469473
end
470474

471475
@doc """
@@ -488,7 +492,9 @@ defmodule Membrane.ChildrenSpec do
488492
else
489493
via_out(builder, :output)
490494
end
491-
|> then(&%Builder{&1 | status: :to_pad, to_pad: pad, to_pad_props: %{}})
495+
|> then(fn %Builder{} = builder ->
496+
%Builder{builder | status: :to_pad, to_pad: pad, to_pad_props: %{}}
497+
end)
492498
|> get_child({Membrane.Bin, :itself})
493499
end
494500

@@ -541,7 +547,7 @@ defmodule Membrane.ChildrenSpec do
541547
"Invalid link specification: input #{inspect(pad)} placed after another input"
542548
end
543549

544-
def via_in(%Builder{links: [%{to: {Membrane.Bin, :itself}} | _]}, pad, _props) do
550+
def via_in(%Builder{links: [%{to: {Membrane.Bin, :itself}} | _rest]}, pad, _props) do
545551
raise ParentError,
546552
"Invalid link specification: input #{inspect(pad)} placed after bin's output"
547553
end
@@ -572,7 +578,9 @@ defmodule Membrane.ChildrenSpec do
572578
else
573579
via_out(builder, :output)
574580
end
575-
|> then(&%Builder{&1 | status: :to_pad, to_pad: pad, to_pad_props: Enum.into(props, %{})})
581+
|> then(fn %Builder{} = builder ->
582+
%Builder{builder | status: :to_pad, to_pad: pad, to_pad_props: Enum.into(props, %{})}
583+
end)
576584
end
577585

578586
@doc """
@@ -598,7 +606,7 @@ defmodule Membrane.ChildrenSpec do
598606
raise ParentError, "Invalid link specification: output #{inspect(pad)} placed after an input"
599607
end
600608

601-
def via_out(%Builder{links: [%{to: {Membrane.Bin, :itself}} | _]}, pad, _props) do
609+
def via_out(%Builder{links: [%{to: {Membrane.Bin, :itself}} | _rest]}, pad, _props) do
602610
raise ParentError,
603611
"Invalid link specification: output #{inspect(pad)} placed after bin's output"
604612
end

lib/membrane/core/child/pad_controller.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ defmodule Membrane.Core.Child.PadController do
6161
map | no_return
6262
def parse_pad_options!(pad_name, options, state) do
6363
{_pad_name, pad_spec} =
64-
PadSpecHandler.get_pads(state) |> Enum.find(fn {k, _} -> k == pad_name end)
64+
PadSpecHandler.get_pads(state) |> Enum.find(fn {k, _desc} -> k == pad_name end)
6565

6666
bunch_field_specs =
6767
Bunch.KVList.map_values(pad_spec.options || [], &Keyword.take(&1, [:default]))

lib/membrane/core/child/pads_specs.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ defmodule Membrane.Core.Child.PadsSpecs do
340340
def generate_docs_from_pads_specs(pads_specs) do
341341
pads_docs =
342342
pads_specs
343-
|> Enum.sort_by(fn {_, config} -> config[:direction] end)
343+
|> Enum.sort_by(fn {_pad_name, config} -> config[:direction] end)
344344
|> Enum.map(&generate_docs_from_pad_specs/1)
345345
|> Enum.reduce(fn x, acc ->
346346
quote do

lib/membrane/core/element.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ defmodule Membrane.Core.Element do
102102
end
103103
end
104104

105+
# Suppress false positive dialyzer warnings resulting from
106+
# broken handling of opaque types - in this case MapSet.t()
107+
# https://github.com/elixir-lang/elixir/issues/14576
108+
@dialyzer {:nowarn_function, do_init: 1}
105109
defp do_init(options) do
106110
Process.link(options.parent_supervisor)
107111

@@ -141,9 +145,9 @@ defmodule Membrane.Core.Element do
141145
state =
142146
%State{
143147
module: options.module,
144-
type: options.module.membrane_element_type(),
145148
name: options.name,
146149
parent_pid: options.parent,
150+
type: options.module.membrane_element_type(),
147151
synchronization: %{
148152
parent_clock: options.parent_clock,
149153
timers: %{},

lib/membrane/core/element/action_handler.ex

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ defmodule Membrane.Core.Element.ActionHandler do
7575
end
7676

7777
@impl CallbackHandler
78-
def handle_action({action, _}, :handle_init, _params, _state)
78+
def handle_action({action, _arg}, :handle_init, _params, _state)
7979
when action not in [:latency, :notify_parent] do
8080
raise ActionError, action: action, reason: {:invalid_callback, :handle_init}
8181
end
8282

8383
@impl CallbackHandler
84-
def handle_action({action, _}, _cb, _params, %State{playback: playback})
84+
def handle_action({action, _arg}, _cb, _params, %State{playback: playback})
8585
when playback != :playing and
8686
action in [
8787
:buffer,
@@ -291,12 +291,13 @@ defmodule Membrane.Core.Element.ActionHandler do
291291
actions
292292
|> Bunch.Enum.chunk_by_prev(
293293
fn
294-
{:buffer, {pad, _}}, {:buffer, {pad, _}} -> true
294+
{:buffer, {pad, _buffer1}}, {:buffer, {pad, _buffer2}} -> true
295295
_prev_action, _action -> false
296296
end,
297297
fn
298-
[{:buffer, {pad, _}} | _] = buffers ->
299-
{:buffer, {pad, buffers |> Enum.map(fn {_, {_, b}} -> [b] end) |> List.flatten()}}
298+
[{:buffer, {pad, _buffer}} | _rest] = buffers ->
299+
{:buffer,
300+
{pad, buffers |> Enum.map(fn {:buffer, {_pad, b}} -> [b] end) |> List.flatten()}}
300301

301302
[other] ->
302303
other

lib/membrane/core/element/auto_flow_controller.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ defmodule Membrane.Core.Element.AutoFlowController do
218218
|> Map.put(:popping_auto_flow_queue?, false)
219219
end
220220

221+
# Suppress false positive dialyzer warnings resulting from
222+
# broken handling of opaque types - in this case MapSet.t()
223+
# https://github.com/elixir-lang/elixir/issues/14576
224+
@dialyzer {:nowarn_function, bump_demand: 1}
221225
defp bump_demand(state) do
222226
if state.effective_flow_control == :pull and
223227
state.satisfied_auto_output_pads == @empty_map_set do

lib/membrane/core/element/event_controller.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ defmodule Membrane.Core.Element.EventController do
55

66
use Bunch
77

8-
alias Membrane.{Event, Pad, Sync}
98
alias Membrane.Core.{CallbackHandler, Events, Message, Telemetry}
109
alias Membrane.Core.Child.PadModel
1110

@@ -19,6 +18,7 @@ defmodule Membrane.Core.Element.EventController do
1918
}
2019

2120
alias Membrane.Core.Element.ManualFlowController.InputQueue
21+
alias Membrane.{Event, Pad, Sync}
2222

2323
require Membrane.Core.Child.PadModel
2424
require Membrane.Core.Message

lib/membrane/core/element/lifecycle_controller.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ defmodule Membrane.Core.Element.LifecycleController do
7373
end
7474

7575
@spec handle_playing(State.t()) :: State.t()
76-
def handle_playing(state) do
76+
def handle_playing(%State{} = state) do
7777
Membrane.Logger.debug("Got play request")
7878

7979
state =

lib/membrane/core/element/manual_flow_controller.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ defmodule Membrane.Core.Element.ManualFlowController do
8080
|> handle_delayed_demands()
8181
end
8282

83-
defp do_supply_demand(pad_ref, state) do
83+
defp do_supply_demand(pad_ref, %State{} = state) do
8484
# marking is state that actual demand supply has been started (note changing back to false when finished)
8585
state = %State{state | delay_demands?: true}
8686

@@ -90,7 +90,7 @@ defmodule Membrane.Core.Element.ManualFlowController do
9090
InputQueue.take(pad_data.input_queue, pad_data.manual_demand_size)
9191

9292
state = PadModel.set_data!(state, pad_ref, :input_queue, new_input_queue)
93-
state = handle_input_queue_output(pad_ref, popped_data, state)
93+
%State{} = state = handle_input_queue_output(pad_ref, popped_data, state)
9494
%State{state | delay_demands?: false}
9595
end
9696

lib/membrane/core/element/playback_queue.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ defmodule Membrane.Core.Element.PlaybackQueue do
1212

1313
@spec eval(State.t()) :: State.t()
1414
def eval(%State{playback_queue: playback_queue} = state) do
15-
state =
15+
%State{} =
16+
state =
1617
playback_queue
1718
|> List.foldr(state, fn function, state -> function.(state) end)
1819

0 commit comments

Comments
 (0)