Skip to content

Commit 7313d26

Browse files
author
José Valim
committed
Remove deprecated branches
1 parent 577a07d commit 7313d26

File tree

9 files changed

+69
-113
lines changed

9 files changed

+69
-113
lines changed

lib/elixir/lib/collectable.ex

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,13 @@ defprotocol Collectable do
2121
shape where just the range limits are stored.
2222
2323
The `Collectable` module was designed to fill the gap left by the
24-
`Enumerable` protocol. It provides two functions: `into/1` and `empty/1`.
25-
26-
`into/1` can be seen as the opposite of `Enumerable.reduce/3`. If
27-
`Enumerable` is about taking values out, `Collectable.into/1` is about
28-
collecting those values into a structure.
24+
`Enumerable` protocol. `into/1` can be seen as the opposite of
25+
`Enumerable.reduce/3`. If `Enumerable` is about taking values out,
26+
`Collectable.into/1` is about collecting those values into a structure.
2927
"""
3028

3129
@type command :: {:cont, term} | :done | :halt
3230

33-
@doc """
34-
Receives a collectable structure and returns an empty one.
35-
"""
36-
@spec empty(t) :: t
37-
def empty(collectable)
38-
3931
@doc """
4032
Returns a function that collects values alongside
4133
the initial accumulation value.
@@ -55,10 +47,6 @@ defprotocol Collectable do
5547
end
5648

5749
defimpl Collectable, for: List do
58-
def empty(_list) do
59-
[]
60-
end
61-
6250
def into(original) do
6351
{[], fn
6452
list, {:cont, x} -> [x|list]
@@ -69,10 +57,6 @@ defimpl Collectable, for: List do
6957
end
7058

7159
defimpl Collectable, for: BitString do
72-
def empty(_bitstring) do
73-
""
74-
end
75-
7660
def into(original) do
7761
{original, fn
7862
acc, {:cont, x} when is_bitstring(x) -> [acc|x]
@@ -83,10 +67,6 @@ defimpl Collectable, for: BitString do
8367
end
8468

8569
defimpl Collectable, for: Map do
86-
def empty(_map) do
87-
%{}
88-
end
89-
9070
def into(original) do
9171
{original, fn
9272
map, {:cont, {k, v}} -> :maps.put(k, v, map)

lib/elixir/lib/enum.ex

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,15 +1798,6 @@ defmodule Enum do
17981798
reverse(collection) |> :lists.reverse
17991799
end
18001800

1801-
@doc false
1802-
def traverse(collection, transform) when is_list(collection) do
1803-
:lists.map(transform, collection)
1804-
end
1805-
1806-
def traverse(collection, transform) do
1807-
into(collection, apply(Collectable, :empty, [collection]), transform)
1808-
end
1809-
18101801
@doc """
18111802
Enumerates the collection, removing all duplicated items.
18121803

lib/elixir/lib/gen_event.ex

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,6 @@ defmodule GenEvent do
355355
@spec add_handler(manager, handler, term, [monitor: boolean]) :: :ok | {:error, term}
356356
def add_handler(manager, handler, args, options \\ []) do
357357
cond do
358-
Keyword.get(options, :link, false) ->
359-
raise ArgumentError, message: "GenEvent.add_handler/4 with link is deprecated and no longer works"
360358
Keyword.get(options, :monitor, false) ->
361359
rpc(manager, {:add_mon_handler, handler, args, self()})
362360
true ->
@@ -486,8 +484,6 @@ defmodule GenEvent do
486484
@spec swap_handler(manager, handler, term, handler, term, [monitor: boolean]) :: :ok | {:error, term}
487485
def swap_handler(manager, handler1, args1, handler2, args2, options \\ []) do
488486
cond do
489-
Keyword.get(options, :link, false) ->
490-
raise ArgumentError, message: "GenEvent.swap_handler/6 with link is deprecated and no longer works"
491487
Keyword.get(options, :monitor, false) ->
492488
rpc(manager, {:swap_mon_handler, handler1, args1, handler2, args2, self()})
493489
true ->

lib/elixir/lib/integer.ex

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ defmodule Integer do
55

66
import Bitwise
77

8-
@doc false
9-
defmacro odd?(n) do
10-
quote do: (unquote(n) &&& 1) == 1
11-
end
12-
138
@doc """
149
Determines if an integer is odd.
1510
@@ -21,11 +16,6 @@ defmodule Integer do
2116
quote do: (unquote(n) &&& 1) == 1
2217
end
2318

24-
@doc false
25-
defmacro even?(n) do
26-
quote do: (unquote(n) &&& 1) == 0
27-
end
28-
2919
@doc """
3020
Determines if an integer is even.
3121

lib/elixir/lib/kernel.ex

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,11 +1875,6 @@ defmodule Kernel do
18751875
quote do: List.Chars.to_char_list(unquote(arg))
18761876
end
18771877

1878-
@doc false
1879-
defmacro nil?(x) do
1880-
quote do: unquote(x) == nil
1881-
end
1882-
18831878
@doc """
18841879
Checks if the given argument is nil or not.
18851880
Allowed in guard clauses.

lib/elixir/lib/record.ex

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,6 @@ defmodule Record do
5656
Macro.escape Record.Extractor.extract(name, opts)
5757
end
5858

59-
@doc false
60-
defmacro record?(data, kind) do
61-
case Macro.Env.in_guard?(__CALLER__) do
62-
true ->
63-
quote do
64-
is_tuple(unquote(data)) and tuple_size(unquote(data)) > 0
65-
and :erlang.element(1, unquote(data)) == unquote(kind)
66-
end
67-
false ->
68-
quote do
69-
result = unquote(data)
70-
is_tuple(result) and tuple_size(result) > 0
71-
and :erlang.element(1, result) == unquote(kind)
72-
end
73-
end
74-
end
75-
7659
@doc """
7760
Checks if the given `data` is a record of `kind`.
7861
@@ -101,23 +84,6 @@ defmodule Record do
10184
end
10285
end
10386

104-
@doc false
105-
defmacro record?(data) do
106-
case Macro.Env.in_guard?(__CALLER__) do
107-
true ->
108-
quote do
109-
is_tuple(unquote(data)) and tuple_size(unquote(data)) > 0
110-
and is_atom(:erlang.element(1, unquote(data)))
111-
end
112-
false ->
113-
quote do
114-
result = unquote(data)
115-
is_tuple(result) and tuple_size(result) > 0
116-
and is_atom(:erlang.element(1, result))
117-
end
118-
end
119-
end
120-
12187
@doc """
12288
Checks if the given `data` is a record.
12389

lib/elixir/lib/stream.ex

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,17 +1017,13 @@ defmodule Stream do
10171017
{:halted, acc}
10181018
end
10191019

1020-
# TODO: We should check this is a two-item tuple once
1021-
# we remove support for the deprecated nil
1022-
# TODO: Support non lists once the previous format
1023-
# is removed
10241020
defp do_resource(next_acc, next_fun, {:cont, acc}, fun, after_fun) do
10251021
try do
10261022
# Optimize the most common cases
10271023
case next_fun.(next_acc) do
10281024
{[], next_acc} -> {:opt, {:cont, acc}, next_acc}
10291025
{[v], next_acc} -> {:opt, fun.(v, acc), next_acc}
1030-
other -> other
1026+
{_, _} = other -> other
10311027
end
10321028
catch
10331029
kind, reason ->
@@ -1042,15 +1038,10 @@ defmodule Stream do
10421038
{list, next_acc} when is_list(list) ->
10431039
do_list_resource(next_acc, next_fun, {:cont, acc}, fun, after_fun,
10441040
&Enumerable.List.reduce(list, &1, fun))
1045-
nil ->
1046-
IO.write :stderr, "warning: returning nil from Stream.resource/3 is deprecated, " <>
1047-
"please return {:halt, acc} instead\n#{Exception.format_stacktrace}"
1048-
do_resource(next_acc, next_fun, {:halt, acc}, fun, after_fun)
1049-
{v, next_acc} ->
1050-
IO.write :stderr, "warning: returning {next, acc} from Stream.resource/3 is deprecated, " <>
1051-
"please return {[val], acc} instead\n#{Exception.format_stacktrace}"
1052-
do_list_resource(next_acc, next_fun, {:cont, acc}, fun, after_fun,
1053-
&Enumerable.List.reduce([v], &1, fun))
1041+
{enum, next_acc} ->
1042+
inner = &do_resource_each(&1, &2, fun)
1043+
do_enum_resource(next_acc, next_fun, {:cont, acc}, fun, after_fun,
1044+
&Enumerable.reduce(enum, &1, inner))
10541045
end
10551046
end
10561047

@@ -1072,6 +1063,33 @@ defmodule Stream do
10721063
end
10731064
end
10741065

1066+
defp do_enum_resource(next_acc, next_fun, {op, acc}, fun, after_fun, reduce) do
1067+
try do
1068+
reduce.({op, [:outer|acc]})
1069+
catch
1070+
kind, reason ->
1071+
stacktrace = System.stacktrace
1072+
after_fun.(next_acc)
1073+
:erlang.raise(kind, reason, stacktrace)
1074+
else
1075+
{:halted, [:outer|acc]} ->
1076+
do_resource(next_acc, next_fun, {:cont, acc}, fun, after_fun)
1077+
{:halted, [:inner|acc]} ->
1078+
do_resource(next_acc, next_fun, {:halt, acc}, fun, after_fun)
1079+
{:done, [_|acc]} ->
1080+
do_resource(next_acc, next_fun, {:cont, acc}, fun, after_fun)
1081+
{:suspended, [_|acc], c} ->
1082+
{:suspended, acc, &do_enum_resource(next_acc, next_fun, &1, fun, after_fun, c)}
1083+
end
1084+
end
1085+
1086+
defp do_resource_each(x, [:outer|acc], f) do
1087+
case f.(x, acc) do
1088+
{:halt, res} -> {:halt, [:inner|res]}
1089+
{op, res} -> {op, [:outer|res]}
1090+
end
1091+
end
1092+
10751093
@doc """
10761094
Emits a sequence of values for the given accumulator.
10771095

lib/elixir/src/elixir_dispatch.erl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -522,19 +522,5 @@ deprecation_message(Warning, Message) ->
522522
Message -> Warning ++ ", " ++ Message
523523
end.
524524

525-
deprecation('Elixir.Collectable', 'empty', 1) ->
526-
true;
527-
deprecation('Elixir.Enum', 'traverse', 2) ->
528-
true;
529-
deprecation('Elixir.Kernel', 'nil?', 1) ->
530-
true;
531-
deprecation('Elixir.Record', 'record?', 1) ->
532-
true;
533-
deprecation('Elixir.Record', 'record?', 2) ->
534-
true;
535-
deprecation('Elixir.Integer', 'even?', 1) ->
536-
true;
537-
deprecation('Elixir.Integer', 'odd?', 1) ->
538-
true;
539525
deprecation(_, _, _) ->
540526
false.

lib/elixir/test/elixir/stream_test.exs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,40 @@ defmodule StreamTest do
480480
assert Process.get(:stream_resource)
481481
end
482482

483+
test "resource/3 halts with inner enum" do
484+
stream = Stream.resource(fn -> 1 end,
485+
fn acc -> {acc..acc+2, acc + 1} end,
486+
fn _ -> Process.put(:stream_resource, true) end)
487+
488+
Process.put(:stream_resource, false)
489+
assert Enum.take(stream, 5) == [1, 2, 3, 2, 3]
490+
assert Process.get(:stream_resource)
491+
end
492+
493+
test "resource/3 closes on errors with inner enum" do
494+
stream = Stream.resource(fn -> 1 end,
495+
fn acc -> {acc..acc+2, acc + 1} end,
496+
fn _ -> Process.put(:stream_resource, true) end)
497+
498+
Process.put(:stream_resource, false)
499+
stream = Stream.map(stream, fn x -> if x > 2, do: throw(:error), else: x end)
500+
assert catch_throw(Enum.to_list(stream)) == :error
501+
assert Process.get(:stream_resource)
502+
end
503+
504+
test "resource/3 is zippable with inner enum" do
505+
stream = Stream.resource(fn -> 1 end,
506+
fn 10 -> {:halt, 10}
507+
acc -> {acc..acc+2, acc + 1}
508+
end,
509+
fn _ -> Process.put(:stream_resource, true) end)
510+
511+
list = Enum.to_list(stream)
512+
Process.put(:stream_resource, false)
513+
assert Enum.zip(list, list) == Enum.zip(stream, stream)
514+
assert Process.get(:stream_resource)
515+
end
516+
483517
test "scan/2" do
484518
stream = Stream.scan(1..5, &(&1 + &2))
485519
assert is_lazy(stream)

0 commit comments

Comments
 (0)