Skip to content

Commit 0f6434d

Browse files
committed
Reduce AST metadata compiled in definitions
1 parent 99b79af commit 0f6434d

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5135,31 +5135,22 @@ defmodule Kernel do
51355135

51365136
unquoted_call = :elixir_quote.has_unquotes(call)
51375137
unquoted_expr = :elixir_quote.has_unquotes(expr)
5138-
escaped_call = :elixir_quote.escape(call, :none, true)
51395138

5140-
escaped_expr =
5141-
case unquoted_expr do
5139+
store =
5140+
case unquoted_expr or unquoted_call do
51425141
true ->
5143-
:elixir_quote.escape(expr, :none, true)
5142+
:elixir_quote.escape({call, expr}, :none, true)
51445143

51455144
false ->
51465145
key = :erlang.unique_integer()
5147-
:elixir_module.write_cache(module, key, expr)
5148-
quote(do: :elixir_module.read_cache(unquote(module), unquote(key)))
5146+
:elixir_module.write_cache(module, key, {call, expr})
5147+
key
51495148
end
51505149

5151-
# Do not check clauses if any expression was unquoted
5152-
check_clauses = not (unquoted_expr or unquoted_call)
51535150
pos = :elixir_locals.cache_env(env)
51545151

51555152
quote do
5156-
:elixir_def.store_definition(
5157-
unquote(kind),
5158-
unquote(check_clauses),
5159-
unquote(escaped_call),
5160-
unquote(escaped_expr),
5161-
unquote(pos)
5162-
)
5153+
:elixir_def.store_definition(unquote(kind), unquote(store), unquote(pos))
51635154
end
51645155
end
51655156

lib/elixir/src/elixir_bootstrap.erl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,22 @@
3535
{defmodule, 2},
3636
{defp, 2}].
3737

38-
define({Line, _S, E}, Kind, Call, Expr) ->
38+
define({Line, _S, #{module := Module} = E}, Kind, Call, Expr) ->
3939
UC = elixir_quote:has_unquotes(Call),
4040
UE = elixir_quote:has_unquotes(Expr),
41-
EscapedCall = elixir_quote:escape(Call, none, true),
42-
EscapedExpr = elixir_quote:escape(Expr, none, true),
43-
Args = [Kind, not(UC or UE), EscapedCall, EscapedExpr, elixir_locals:cache_env(E#{line := Line})],
41+
42+
Store =
43+
case UC or UE of
44+
true ->
45+
elixir_quote:escape({Call, Expr}, none, true);
46+
47+
false ->
48+
Key = erlang:unique_integer(),
49+
elixir_module:write_cache(Module, Key, {Call, Expr}),
50+
Key
51+
end,
52+
53+
Args = [Kind, Store, elixir_locals:cache_env(E#{line := Line})],
4454
{{'.', [], [elixir_def, store_definition]}, [], Args}.
4555

4656
unless_loaded(Fun, Args, Callback) ->

lib/elixir/src/elixir_def.erl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Holds the logic responsible for function definitions (def(p) and defmacro(p)).
22
-module(elixir_def).
33
-export([setup/1, reset_last/1, local_for/5, external_for/5,
4-
take_definition/2, store_definition/5, store_definition/9,
4+
take_definition/2, store_definition/3, store_definition/9,
55
fetch_definitions/2, format_error/1]).
66
-include("elixir.hrl").
77
-define(last_def, {elixir, last_def}).
@@ -127,8 +127,15 @@ head_and_definition_meta(false, _Meta, _HeadDefaults, _All) ->
127127

128128
%% Section for storing definitions
129129

130-
store_definition(Kind, CheckClauses, Call, Body, Pos) ->
131-
#{line := Line} = E = elixir_locals:get_cached_env(Pos),
130+
store_definition(Kind, {Call, Body}, Pos) ->
131+
E = elixir_locals:get_cached_env(Pos),
132+
store_definition(Kind, false, Call, Body, E);
133+
store_definition(Kind, Key, Pos) ->
134+
#{module := Module} = E = elixir_locals:get_cached_env(Pos),
135+
{Call, Body} = elixir_module:read_cache(Module, Key),
136+
store_definition(Kind, true, Call, Body, E).
137+
138+
store_definition(Kind, CheckClauses, Call, Body, #{line := Line} = E) ->
132139
{NameAndArgs, Guards} = elixir_utils:extract_guards(Call),
133140

134141
{Name, Args} = case NameAndArgs of

0 commit comments

Comments
 (0)