Skip to content

Commit 43b54f9

Browse files
author
José Valim
committed
Do not serialize references, closes #6393
1 parent 9dfc7a8 commit 43b54f9

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3565,7 +3565,6 @@ defmodule Kernel do
35653565
defp define(kind, call, expr, env) do
35663566
module = assert_module_scope(env, kind, 2)
35673567
assert_no_function_scope(env, kind, 2)
3568-
table = :elixir_module.data_table(module)
35693568

35703569
{escaped_call, unquoted_call} = :elixir_quote.escape(call, true)
35713570
{escaped_expr, unquoted_expr} = :elixir_quote.escape(expr, true)
@@ -3575,14 +3574,14 @@ defmodule Kernel do
35753574
true ->
35763575
escaped_expr
35773576
false ->
3578-
key = {:cache_def, :erlang.unique_integer()}
3579-
:ets.insert(table, {key, expr})
3580-
quote do: :ets.lookup_element(unquote(table), unquote(key), 2)
3577+
key = :erlang.unique_integer()
3578+
:elixir_module.write_cache(module, key, expr)
3579+
quote do: :elixir_module.read_cache(unquote(module), unquote(key))
35813580
end
35823581

35833582
# Do not check clauses if any expression was unquoted
35843583
check_clauses = not(unquoted_expr or unquoted_call)
3585-
pos = :elixir_locals.cache_env(table, env)
3584+
pos = :elixir_locals.cache_env(env)
35863585

35873586
quote do
35883587
:elixir_def.store_definition(unquote(kind), unquote(check_clauses),

lib/elixir/src/elixir_erl.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ elixir_to_erl(Function) when is_function(Function) ->
121121
false ->
122122
error(badarg)
123123
end;
124-
elixir_to_erl(PidOrRef) when is_pid(PidOrRef); is_reference(PidOrRef) ->
124+
elixir_to_erl(Pid) when is_pid(Pid) ->
125125
elixir_erl:remote(0, erlang, binary_to_term,
126-
[elixir_erl:elixir_to_erl(term_to_binary(PidOrRef))]);
126+
[elixir_erl:elixir_to_erl(term_to_binary(Pid))]);
127127
elixir_to_erl(_Other) ->
128128
error(badarg).
129129

lib/elixir/src/elixir_expand.erl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,15 @@ expand(Function, E) when is_function(Function) ->
448448
end;
449449

450450

451-
expand(PidOrRef, E) when is_pid(PidOrRef); is_reference(PidOrRef) ->
451+
expand(Pid, E) when is_pid(Pid) ->
452452
case ?key(E, function) of
453453
nil ->
454-
{PidOrRef, E};
454+
{Pid, E};
455455
Function ->
456456
%% TODO: Make me an error on 2.0
457457
elixir_errors:form_warn([], ?key(E, file), ?MODULE,
458-
{invalid_pid_or_ref_in_function, PidOrRef, Function}),
459-
{PidOrRef, E}
458+
{invalid_pid_in_function, Pid, Function}),
459+
{Pid, E}
460460
end;
461461

462462
expand(Other, E) when is_number(Other); is_atom(Other); is_binary(Other) ->
@@ -949,9 +949,9 @@ format_error({invalid_local_invocation, Context, {Name, _, Args} = Call}) ->
949949
format_error({invalid_remote_invocation, Context, Receiver, Right, Arity}) ->
950950
io_lib:format("cannot invoke remote function ~ts.~ts/~B inside ~ts",
951951
['Elixir.Macro':to_string(Receiver), Right, Arity, Context]);
952-
format_error({invalid_pid_or_ref_in_function, PidOrRef, {Name, Arity}}) ->
953-
io_lib:format("cannot compile PID/Reference ~ts inside quoted expression for function ~ts/~B",
954-
['Elixir.Kernel':inspect(PidOrRef, []), Name, Arity]);
952+
format_error({invalid_pid_in_function, Pid, {Name, Arity}}) ->
953+
io_lib:format("cannot compile PID ~ts inside quoted expression for function ~ts/~B",
954+
['Elixir.Kernel':inspect(Pid, []), Name, Arity]);
955955
format_error({unsupported_option, Kind, Key}) ->
956956
io_lib:format("unsupported option ~ts given to ~s",
957957
['Elixir.Macro':to_string(Key), Kind]);

lib/elixir/src/elixir_locals.erl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%% Module responsible for tracking invocations of module calls.
22
-module(elixir_locals).
33
-export([
4-
setup/1, cleanup/1, cache_env/1, cache_env/2, get_cached_env/1,
4+
setup/1, cleanup/1, cache_env/1, get_cached_env/1,
55
record_local/2, record_local/3, record_import/4,
66
record_definition/3, record_defaults/4, reattach/5,
77
ensure_no_import_conflict/3, warn_unused_local/3, format_error/1
@@ -60,10 +60,8 @@ if_tracker(Module, Default, Callback) ->
6060

6161
%% CACHING
6262

63-
cache_env(#{module := Module} = E) ->
64-
cache_env(elixir_module:data_table(Module), E).
65-
66-
cache_env(Table, #{line := Line} = E) ->
63+
cache_env(#{line := Line, module := Module} = E) ->
64+
Table = elixir_module:data_table(Module),
6765
Cache = E#{line := nil, vars := []},
6866

6967
Pos =
@@ -77,10 +75,10 @@ cache_env(Table, #{line := Line} = E) ->
7775
Key
7876
end,
7977

80-
{Table, {Line, Pos}}.
78+
{Module, {Line, Pos}}.
8179

82-
get_cached_env({Table, {Line, Pos}}) ->
83-
(ets:lookup_element(Table, {cache_env, Pos}, 2))#{line := Line};
80+
get_cached_env({Module, {Line, Pos}}) ->
81+
(ets:lookup_element(elixir_module:data_table(Module), {cache_env, Pos}, 2))#{line := Line};
8482
get_cached_env(Env) ->
8583
Env.
8684

lib/elixir/src/elixir_module.erl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
-module(elixir_module).
22
-export([data_table/1, defs_table/1, is_open/1, delete_doc/6,
33
compile/4, expand_callback/6, format_error/1,
4-
compiler_modules/0, delete_impl/6]).
4+
compiler_modules/0, delete_impl/6,
5+
write_cache/3, read_cache/2]).
56
-include("elixir.hrl").
67

78
-define(lexical_attr, {elixir, lexical_tracker}).
@@ -39,6 +40,12 @@ delete_impl(#{module := Module}, _, _, _, _, _) ->
3940
ets:delete(data_table(Module), impl),
4041
ok.
4142

43+
write_cache(Module, Key, Value) ->
44+
ets:insert(data_table(Module), {{cache, Key}, Value}).
45+
46+
read_cache(Module, Key) ->
47+
ets:lookup_element(data_table(Module), {cache, Key}, 2).
48+
4249
%% Compilation hook
4350

4451
compile(Module, Block, Vars, #{line := Line} = Env) when is_atom(Module) ->

0 commit comments

Comments
 (0)