summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Meadows-Jönsson <eric.meadows.jonsson@gmail.com>2019-10-08 14:39:05 +0200
committerGitHub <noreply@github.com>2019-10-08 14:39:05 +0200
commit9f334a73caf72aa4e7d5e4a5b225e2add5a7c658 (patch)
tree0331472e83ec38d71a89539cc0237b706e54f1df
parentb3debbe1e8511b55383d791284716212bd341629 (diff)
downloadelixir-9f334a73caf72aa4e7d5e4a5b225e2add5a7c658.tar.gz
Move map.ex to bootstrap (#9389)
-rw-r--r--lib/elixir/lib/collectable.ex2
-rw-r--r--lib/elixir/lib/inspect.ex14
-rw-r--r--lib/elixir/lib/kernel/lexical_tracker.ex22
-rw-r--r--lib/elixir/lib/map_set.ex6
-rw-r--r--lib/elixir/lib/module/checker.ex8
-rw-r--r--lib/elixir/lib/module/parallel_checker.ex22
-rw-r--r--lib/elixir/lib/module/types.ex8
-rw-r--r--lib/elixir/lib/module/types/infer.ex92
-rw-r--r--lib/elixir/lib/supervisor.ex2
-rw-r--r--lib/elixir/src/elixir_compiler.erl1
10 files changed, 82 insertions, 95 deletions
diff --git a/lib/elixir/lib/collectable.ex b/lib/elixir/lib/collectable.ex
index bb87a0b0a..b6d73795d 100644
--- a/lib/elixir/lib/collectable.ex
+++ b/lib/elixir/lib/collectable.ex
@@ -143,7 +143,7 @@ end
defimpl Collectable, for: Map do
def into(original) do
fun = fn
- map, {:cont, {k, v}} -> :maps.put(k, v, map)
+ map, {:cont, {k, v}} -> Map.put(map, k, v)
map, :done -> map
_, :halt -> :ok
end
diff --git a/lib/elixir/lib/inspect.ex b/lib/elixir/lib/inspect.ex
index 4d9887227..d791f4e05 100644
--- a/lib/elixir/lib/inspect.ex
+++ b/lib/elixir/lib/inspect.ex
@@ -32,9 +32,9 @@ defprotocol Inspect do
end
The [`concat/1`](`Inspect.Algebra.concat/1`) function comes from `Inspect.Algebra` and it
- concatenates algebra documents together. In the example above it is
- concatenating the string `"MapSet<"`, the document returned by
- `Inspect.Algebra.to_doc/2`, and the final string `">"`. All strings are
+ concatenates algebra documents together. In the example above it is
+ concatenating the string `"MapSet<"`, the document returned by
+ `Inspect.Algebra.to_doc/2`, and the final string `">"`. All strings are
valid algebra documents that keep their formatting when pretty printed.
Since regular strings are valid entities in an algebra document,
@@ -252,7 +252,7 @@ defimpl Inspect, for: Map do
end
def inspect(map, name, opts) do
- map = :maps.to_list(map)
+ map = Map.to_list(map)
open = color("%" <> name <> "{", :map, opts)
sep = color(",", :map, opts)
close = color("}", :map, opts)
@@ -442,8 +442,8 @@ defimpl Inspect, for: Any do
_ -> Inspect.Map.inspect(struct, opts)
else
dunder ->
- if :maps.keys(dunder) == :maps.keys(struct) do
- pruned = :maps.remove(:__exception__, :maps.remove(:__struct__, struct))
+ if Map.keys(dunder) == Map.keys(struct) do
+ pruned = Map.drop(struct, [:__struct__, :__exception__])
Inspect.Map.inspect(pruned, Identifier.inspect_as_atom(module), opts)
else
Inspect.Map.inspect(struct, opts)
@@ -455,7 +455,7 @@ defimpl Inspect, for: Any do
# Use the :limit option and an extra element to force
# `container_doc/6` to append "...".
opts = %{opts | limit: min(opts.limit, map_size(map))}
- map = :maps.to_list(map) ++ ["..."]
+ map = Map.to_list(map) ++ ["..."]
open = color("#" <> name <> "<", :map, opts)
sep = color(",", :map, opts)
diff --git a/lib/elixir/lib/kernel/lexical_tracker.ex b/lib/elixir/lib/kernel/lexical_tracker.ex
index 5de2c90f9..9b98e5ef8 100644
--- a/lib/elixir/lib/kernel/lexical_tracker.ex
+++ b/lib/elixir/lib/kernel/lexical_tracker.ex
@@ -120,12 +120,12 @@ defmodule Kernel.LexicalTracker do
end
def handle_call(:alias_references, _from, state) do
- {compile, runtime} = partition(:maps.to_list(state.references), [], [])
- {:reply, {compile, :maps.keys(state.structs), runtime}, state}
+ {compile, runtime} = partition(Map.to_list(state.references), [], [])
+ {:reply, {compile, Map.keys(state.structs), runtime}, state}
end
def handle_call({:read_cache, key}, _from, %{cache: cache} = state) do
- {:reply, :maps.get(key, cache), state}
+ {:reply, Map.get(cache, key), state}
end
def handle_call(:stop, _from, state) do
@@ -133,11 +133,11 @@ defmodule Kernel.LexicalTracker do
end
def handle_cast({:write_cache, key, value}, %{cache: cache} = state) do
- {:noreply, %{state | cache: :maps.put(key, value, cache)}}
+ {:noreply, %{state | cache: Map.put(cache, key, value)}}
end
def handle_cast({:remote_struct, module}, state) do
- structs = :maps.put(module, true, state.structs)
+ structs = Map.put(state.structs, module, true)
{:noreply, %{state | structs: structs}}
end
@@ -168,7 +168,7 @@ defmodule Kernel.LexicalTracker do
directives =
state.directives
|> Enum.reject(&match?({{:import, {^module, _, _}}, _}, &1))
- |> :maps.from_list()
+ |> Map.new()
|> add_directive(module, line, warn, :import)
directives =
@@ -209,12 +209,12 @@ defmodule Kernel.LexicalTracker do
# Callbacks helpers
defp add_reference(references, module, :compile) when is_atom(module),
- do: :maps.put(module, :compile, references)
+ do: Map.put(references, module, :compile)
defp add_reference(references, module, :runtime) when is_atom(module) do
- case :maps.find(module, references) do
+ case Map.fetch(references, module) do
{:ok, _} -> references
- :error -> :maps.put(module, :runtime, references)
+ :error -> Map.put(references, module, :runtime)
end
end
@@ -235,10 +235,10 @@ defmodule Kernel.LexicalTracker do
# If the value is true, it was imported/aliased and used
defp add_directive(directives, module_or_mfa, line, warn, tag) do
marker = if warn, do: line, else: true
- :maps.put({tag, module_or_mfa}, marker, directives)
+ Map.put(directives, {tag, module_or_mfa}, marker)
end
defp add_dispatch(directives, module_or_mfa, tag) do
- :maps.put({tag, module_or_mfa}, true, directives)
+ Map.put(directives, {tag, module_or_mfa}, true)
end
end
diff --git a/lib/elixir/lib/map_set.ex b/lib/elixir/lib/map_set.ex
index 92cbdc45c..1849b7e38 100644
--- a/lib/elixir/lib/map_set.ex
+++ b/lib/elixir/lib/map_set.ex
@@ -105,7 +105,7 @@ defmodule MapSet do
end
defp new_from_list([], acc) do
- :maps.from_list(acc)
+ Map.new(acc)
end
defp new_from_list([element | rest], acc) do
@@ -113,7 +113,7 @@ defmodule MapSet do
end
defp new_from_list_transform([], _fun, acc) do
- :maps.from_list(acc)
+ Map.new(acc)
end
defp new_from_list_transform([element | rest], fun, acc) do
@@ -171,7 +171,7 @@ defmodule MapSet do
%{map_set | map: Map.drop(map1, Map.keys(map2))}
end
- defp filter_not_in([], _map2, acc), do: :maps.from_list(acc)
+ defp filter_not_in([], _map2, acc), do: Map.new(acc)
defp filter_not_in([key | rest], map2, acc) do
case map2 do
diff --git a/lib/elixir/lib/module/checker.ex b/lib/elixir/lib/module/checker.ex
index e61bf48e7..afaf5527f 100644
--- a/lib/elixir/lib/module/checker.ex
+++ b/lib/elixir/lib/module/checker.ex
@@ -56,13 +56,13 @@ defmodule Module.Checker do
defp build_chunk(map, types) do
exports = ParallelChecker.definitions_to_exports(map.definitions)
- deprecated = :maps.from_list(map.deprecated)
- types = :maps.from_list(types)
+ deprecated = Map.new(map.deprecated)
+ types = Map.new(types)
exports =
Enum.map(exports, fn {function, kind} ->
- deprecated_reason = :maps.get(function, deprecated, nil)
- type = :maps.get(function, types, nil)
+ deprecated_reason = Map.get(deprecated, function)
+ type = Map.get(types, function)
{function, %{kind: kind, deprecated_reason: deprecated_reason, type: type}}
end)
diff --git a/lib/elixir/lib/module/parallel_checker.ex b/lib/elixir/lib/module/parallel_checker.ex
index 9f502a406..41d4f8cca 100644
--- a/lib/elixir/lib/module/parallel_checker.ex
+++ b/lib/elixir/lib/module/parallel_checker.ex
@@ -21,7 +21,7 @@ defmodule Module.ParallelChecker do
start(server)
compiled_binaries = Enum.map(compiled_modules, fn {map, binary} -> {map.module, binary} end)
- old_binaries = :maps.from_list(compiled_binaries ++ runtime_binaries)
+ old_binaries = Map.new(compiled_binaries ++ runtime_binaries)
collect_results(old_binaries, [], [])
end
@@ -32,7 +32,7 @@ defmodule Module.ParallelChecker do
defp collect_results(old_binaries, binaries, warnings) do
receive do
{__MODULE__, module, chunk, new_warnings} ->
- {binary, old_binaries} = :maps.take(module, old_binaries)
+ {binary, old_binaries} = Map.pop(old_binaries, module)
binaries = [{module, add_chunk(chunk, binary)} | binaries]
warnings = new_warnings ++ warnings
@@ -130,19 +130,19 @@ defmodule Module.ParallelChecker do
def handle_call({:lock, module}, from, %{waiting: waiting} = state) do
case waiting do
%{^module => froms} ->
- waiting = :maps.put(module, [from | froms], state.waiting)
+ waiting = Map.put(state.waiting, module, [from | froms])
{:noreply, %{state | waiting: waiting}}
%{} ->
- waiting = :maps.put(module, [], state.waiting)
+ waiting = Map.put(state.waiting, module, [])
{:reply, true, %{state | waiting: waiting}}
end
end
def handle_call({:unlock, module}, _from, %{waiting: waiting} = state) do
- froms = :maps.get(module, waiting)
+ froms = Map.fetch!(waiting, module)
Enum.each(froms, &:gen_server.reply(&1, false))
- waiting = :maps.remove(module, waiting)
+ waiting = Map.delete(waiting, module)
{:reply, :ok, %{state | waiting: waiting}}
end
@@ -241,7 +241,7 @@ defmodule Module.ParallelChecker do
defp cache_from_module_map(ets, map) do
exports = [{{:__info__, 1}, :def} | definitions_to_exports(map.definitions)]
- deprecated = :maps.from_list(map.deprecated)
+ deprecated = Map.new(map.deprecated)
cache_info(ets, map.module, exports, deprecated)
end
@@ -256,17 +256,17 @@ defmodule Module.ParallelChecker do
end
defp info_exports(module) do
- :maps.from_list(
+ Map.new(
[{{:__info__, 1}, :def}] ++
Enum.map(module.__info__(:macros), &{&1, :defmacro}) ++
Enum.map(module.__info__(:functions), &{&1, :def})
)
rescue
- _ -> :maps.from_list(Enum.map(module.module_info(:exports), &{&1, :def}))
+ _ -> Map.new(Enum.map(module.module_info(:exports), &{&1, :def}))
end
defp info_deprecated(module) do
- :maps.from_list(module.__info__(:deprecated))
+ Map.new(module.__info__(:deprecated))
rescue
_ -> %{}
end
@@ -274,7 +274,7 @@ defmodule Module.ParallelChecker do
defp cache_info(ets, module, exports, deprecated) do
exports =
Enum.map(exports, fn {{fun, arity}, kind} ->
- reason = :maps.get({fun, arity}, deprecated, nil)
+ reason = Map.get(deprecated, {fun, arity})
:ets.insert(ets, {{:export, {module, fun, arity}}, kind, reason})
{{fun, arity}, kind}
diff --git a/lib/elixir/lib/module/types.ex b/lib/elixir/lib/module/types.ex
index 9573aef44..d2d282bae 100644
--- a/lib/elixir/lib/module/types.ex
+++ b/lib/elixir/lib/module/types.ex
@@ -130,12 +130,12 @@ defmodule Module.Types do
# Lift type variable to its infered (hopefully concrete) types from the context
defp do_lift_type({:var, var}, context) do
- case :maps.find(var, context.lifted_types) do
+ case Map.fetch(context.lifted_types, var) do
{:ok, lifted_var} ->
{{:var, lifted_var}, context}
:error ->
- case :maps.find(var, context.types) do
+ case Map.fetch(context.types, var) do
{:ok, :unbound} ->
new_lifted_var(var, context)
@@ -143,7 +143,7 @@ defmodule Module.Types do
# Remove visited types to avoid infinite loops
# then restore after we are done recursing on vars
types = context.types
- context = %{context | types: :maps.remove(var, context.types)}
+ context = %{context | types: Map.delete(context.types, var)}
{type, context} = do_lift_type(type, context)
{type, %{context | types: types}}
@@ -179,7 +179,7 @@ defmodule Module.Types do
end
defp new_lifted_var(original_var, context) do
- types = :maps.put(original_var, context.lifted_counter, context.lifted_types)
+ types = Map.put(context.lifted_types, original_var, context.lifted_counter)
counter = context.lifted_counter + 1
type = {:var, context.lifted_counter}
diff --git a/lib/elixir/lib/module/types/infer.ex b/lib/elixir/lib/module/types/infer.ex
index 2b5f6642a..ac61e4a3a 100644
--- a/lib/elixir/lib/module/types/infer.ex
+++ b/lib/elixir/lib/module/types/infer.ex
@@ -345,7 +345,7 @@ defmodule Module.Types.Infer do
case arg_types do
[{:var, index} | rest_arg_types] when type_guard? ->
guard_sources =
- :maps.update_with(index, &[:guarded | &1], [:guarded], context.guard_sources)
+ Map.update(context.guard_sources, index, [:guarded], &[:guarded | &1])
{rest_arg_types, guard_sources}
@@ -356,7 +356,7 @@ defmodule Module.Types.Infer do
guard_sources =
Enum.reduce(arg_types, guard_sources, fn
{:var, index}, guard_sources ->
- :maps.update_with(index, &[:fail | &1], [:fail], guard_sources)
+ Map.update(guard_sources, index, [:fail], &[:fail | &1])
_, guard_sources ->
guard_sources
@@ -370,7 +370,7 @@ defmodule Module.Types.Infer do
end
def of_guard(var, _stack, context) when is_var(var) do
- type = :maps.get(var_name(var), context.vars)
+ type = Map.fetch!(context.vars, var_name(var))
{:ok, type, context}
end
@@ -380,8 +380,8 @@ defmodule Module.Types.Infer do
end
defp fresh_context(context) do
- types = :maps.from_list(Enum.map(context.types, fn {var, _} -> {var, :unbound} end))
- traces = :maps.from_list(Enum.map(context.traces, fn {var, _} -> {var, []} end))
+ types = Map.new(context.types, fn {var, _} -> {var, :unbound} end)
+ traces = Map.new(context.traces, fn {var, _} -> {var, []} end)
%{context | types: types, traces: traces}
end
@@ -406,7 +406,7 @@ defmodule Module.Types.Infer do
defp unify_new_types(context, stack, new_context) do
context = merge_traces(context, new_context)
- reduce_ok(:maps.to_list(new_context.types), context, fn
+ reduce_ok(Map.to_list(new_context.types), context, fn
{_index, :unbound}, context ->
{:ok, context}
@@ -423,13 +423,7 @@ defmodule Module.Types.Infer do
defp merge_guard_sources(sources) do
Enum.reduce(sources, fn left, right ->
- :maps.fold(
- fn index, sources, guard_sources ->
- :maps.update_with(index, &join_guard_source(sources, &1), sources, guard_sources)
- end,
- right,
- left
- )
+ Map.merge(left, right, fn _index, left, right -> join_guard_source(left, right) end)
end)
end
@@ -445,23 +439,15 @@ defmodule Module.Types.Infer do
end
defp and_guard_sources(left, right) do
- :maps.fold(
- fn index, sources, guard_sources ->
- :maps.update_with(index, &and_guard_source(sources, &1), sources, guard_sources)
- end,
- right,
- left
- )
- end
-
- defp and_guard_source(left, right) do
- # When the failing guard function wont fail due to type check function before it,
- # for example: is_list(x) and length(x)
- if :guarded in left and :fail in right do
- [:guarded_fail]
- else
- join_guard_source(left, right)
- end
+ Map.merge(left, right, fn _index, left, right ->
+ # When the failing guard function wont fail due to type check function before it,
+ # for example: is_list(x) and length(x)
+ if :guarded in left and :fail in right do
+ [:guarded_fail]
+ else
+ join_guard_source(left, right)
+ end
+ end)
end
defp merge_traces(context, new_context) do
@@ -479,7 +465,7 @@ defmodule Module.Types.Infer do
defp merge_context_or(context, stack, left, right) do
context =
- case {:maps.to_list(left.types), :maps.to_list(right.types)} do
+ case {Map.to_list(left.types), Map.to_list(right.types)} do
{[{index, :unbound}], [{index, type}]} ->
refine_var(index, type, stack, context)
@@ -489,10 +475,10 @@ defmodule Module.Types.Infer do
{[{index, left_type}], [{index, right_type}]} ->
# Only include right side if left side is from type guard such as is_list(x),
# do not refine in case of length(x)
- left_guard_sources = :maps.get(index, left.guard_sources, [])
+ left_guard_sources = Map.get(left.guard_sources, index, [])
if :fail in left_guard_sources do
- guard_sources = :maps.put(index, [:fail], context.guard_sources)
+ guard_sources = Map.put(context.guard_sources, index, [:fail])
context = %{context | guard_sources: guard_sources}
refine_var(index, left_type, stack, context)
else
@@ -509,7 +495,7 @@ defmodule Module.Types.Infer do
{left_types, _right_types} ->
Enum.reduce(left_types, context, fn {index, left_type}, context ->
- left_guard_sources = :maps.get(index, left.guard_sources, [])
+ left_guard_sources = Map.get(left.guard_sources, index, [])
if :fail in left_guard_sources do
guard_sources =
@@ -532,7 +518,7 @@ defmodule Module.Types.Infer do
defp invert_types(stack, context) do
Enum.reduce(context.types, context, fn {index, type}, context ->
- sources = :maps.get(index, context.guard_sources, [])
+ sources = Map.get(context.guard_sources, index, [])
cond do
:guarded_fail in sources ->
@@ -541,7 +527,7 @@ defmodule Module.Types.Infer do
:guarded in sources ->
# Remove traces from inside `not(...)` when we invert the type
# to avoid confusing error messages
- context = %{context | traces: :maps.put(index, [], context.traces)}
+ context = %{context | traces: Map.put(context.traces, index, [])}
refine_var(index, invert_type(type, context), stack, context)
true ->
@@ -657,7 +643,7 @@ defmodule Module.Types.Infer do
end
defp do_unify(type, {:var, var}, stack, context) do
- case :maps.get(var, context.types) do
+ case Map.fetch!(context.types, var) do
:unbound ->
context = refine_var(var, type, stack, context)
stack = push_unify_stack(var, stack)
@@ -773,12 +759,12 @@ defmodule Module.Types.Infer do
end
defp variable_same?(left, right, context) do
- case :maps.find(left, context.types) do
+ case Map.fetch(context.types, left) do
{:ok, {:var, new_left}} ->
variable_same?(new_left, right, context)
_ ->
- case :maps.find(right, context.types) do
+ case Map.fetch(context.types, right) do
{:ok, {:var, new_right}} -> variable_same?(left, new_right, context)
_ -> false
end
@@ -794,16 +780,16 @@ defmodule Module.Types.Infer do
If the variable has already been added, return the existing type variable.
"""
def new_var(var, context) do
- case :maps.find(var_name(var), context.vars) do
+ case Map.fetch(context.vars, var_name(var)) do
{:ok, type} ->
{type, context}
:error ->
type = {:var, context.counter}
- vars = :maps.put(var_name(var), type, context.vars)
- types_to_vars = :maps.put(context.counter, var, context.types_to_vars)
- types = :maps.put(context.counter, :unbound, context.types)
- traces = :maps.put(context.counter, [], context.traces)
+ vars = Map.put(context.vars, var_name(var), type)
+ types_to_vars = Map.put(context.types_to_vars, context.counter, var)
+ types = Map.put(context.types, context.counter, :unbound)
+ traces = Map.put(context.traces, context.counter, [])
context = %{
context
@@ -819,21 +805,21 @@ defmodule Module.Types.Infer do
end
defp refine_var(var, type, stack, context) do
- types = :maps.put(var, type, context.types)
+ types = Map.put(context.types, var, type)
context = %{context | types: types}
trace_var(var, type, stack, context)
end
defp remove_var(var, context) do
- types = :maps.remove(var, context.types)
- traces = :maps.remove(var, context.traces)
+ types = Map.delete(context.types, var)
+ traces = Map.delete(context.traces, var)
%{context | types: types, traces: traces}
end
defp trace_var(var, type, %{trace: true, expr_stack: expr_stack} = _stack, context) do
line = get_meta(hd(expr_stack))[:line]
trace = {type, expr_stack, {context.file, line}}
- traces = :maps.update_with(var, &[trace | &1], context.traces)
+ traces = Map.update!(context.traces, var, &[trace | &1])
%{context | traces: traces}
end
@@ -847,7 +833,7 @@ defmodule Module.Types.Infer do
# Bad: `{var} = var`
# Good: `x = y; y = z; z = x`
defp recursive_type?({:var, var} = parent, parents, context) do
- case :maps.get(var, context.types) do
+ case Map.fetch!(context.types, var) do
:unbound ->
false
@@ -964,9 +950,9 @@ defmodule Module.Types.Infer do
stack = Enum.uniq(stack.unify_stack)
Enum.flat_map(stack, fn var_index ->
- case :maps.find(var_index, context.traces) do
+ case Map.fetch(context.traces, var_index) do
{:ok, traces} ->
- expr_var = :maps.get(var_index, context.types_to_vars)
+ expr_var = Map.fetch!(context.types_to_vars, var_index)
Enum.map(traces, &{expr_var, &1})
_other ->
@@ -981,7 +967,7 @@ defmodule Module.Types.Infer do
Enum.flat_map(traces, fn {var, {type, [expr | _], location}} ->
case type do
{:var, var_index} ->
- var2 = :maps.get(var_index, context.types_to_vars)
+ var2 = Map.fetch!(context.types_to_vars, var_index)
[{var, {:var, var2, expr, location}}]
_ ->
@@ -1010,7 +996,7 @@ defmodule Module.Types.Infer do
defp get_meta(_other), do: []
defp guard_signature(name, arity) do
- :maps.get({name, arity}, @guard_functions)
+ Map.fetch!(@guard_functions, {name, arity})
end
defp type_guard?(name) do
diff --git a/lib/elixir/lib/supervisor.ex b/lib/elixir/lib/supervisor.ex
index ea6626993..02b474af8 100644
--- a/lib/elixir/lib/supervisor.ex
+++ b/lib/elixir/lib/supervisor.ex
@@ -967,7 +967,7 @@ defmodule Supervisor do
workers: non_neg_integer
}
def count_children(supervisor) do
- call(supervisor, :count_children) |> :maps.from_list()
+ call(supervisor, :count_children) |> Map.new()
end
@doc """
diff --git a/lib/elixir/src/elixir_compiler.erl b/lib/elixir/src/elixir_compiler.erl
index 6272f0cc5..1873ad40e 100644
--- a/lib/elixir/src/elixir_compiler.erl
+++ b/lib/elixir/src/elixir_compiler.erl
@@ -157,6 +157,7 @@ bootstrap_main() ->
<<"lib/elixir/lib/protocol.ex">>,
<<"lib/elixir/lib/stream/reducers.ex">>,
<<"lib/elixir/lib/enum.ex">>,
+ <<"lib/elixir/lib/map.ex">>,
<<"lib/elixir/lib/inspect/algebra.ex">>,
<<"lib/elixir/lib/inspect.ex">>,
<<"lib/elixir/lib/access.ex">>,