Skip to content

Commit fbb06f2

Browse files
author
José Valim
committed
Record each definition on tracker as soon as defined
1 parent ffc91e3 commit fbb06f2

File tree

6 files changed

+17
-20
lines changed

6 files changed

+17
-20
lines changed

lib/elixir/include/elixir.hrl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
name_args=false, %% when true, it means arguments should be named
1717
module=nil, %% the current module
1818
function=nil, %% the current function
19-
function_kind=nil, %% the current function kind
2019
vars=[], %% a dict of defined variables and their alias
2120
temp_vars=[], %% a dict of all variables defined in a particular assign
2221
clause_vars=nil, %% a dict of all variables defined in a particular clause

lib/elixir/lib/macro/env.ex

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ defmodule Macro.Env do
1212
* `function` - a tuple as `{ atom, integer` }, where the first
1313
element is the function name and the seconds its arity. Returns
1414
`nil` if not inside a function
15-
* `function_kind` - the kind of the function (`def`, `defp`, etc)
1615
* `aliases` - a list of two item tuples, where the first
1716
item is the aliased name and the second the actual name
1817
* `context` - the context of the environment. It can be nil
@@ -32,15 +31,13 @@ defmodule Macro.Env do
3231
@type functions :: [{ module, [name_arity] }]
3332
@type macros :: [{ module, [name_arity] }]
3433
@type context_modules :: [module]
35-
@type function_kind :: :def | :defp | :defmacro | :defmacrop
3634

3735
fields = [:module, :file, :line, :function, :aliases, :context, :requires,
38-
:functions, :macros, :context_modules, :function_kind]
36+
:functions, :macros, :context_modules]
3937

4038
types = quote do: [module: module, file: file, line: line,
4139
function: name_arity, aliases: aliases, requires: requires,
42-
functions: functions, macros: macros, context_modules: context_modules,
43-
function_kind: function_kind]
40+
functions: functions, macros: macros, context_modules: context_modules]
4441

4542
Record.deffunctions(fields, __MODULE__)
4643
Record.deftypes(fields, types, __MODULE__)

lib/elixir/lib/module/dispatch_tracker.ex

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,6 @@ defmodule Module.DispatchTracker do
158158
# clauses a private function have.
159159
@doc false
160160
def collect_unused_locals(pid, private) do
161-
# Add a vertex for each private given
162-
lc { tuple, kind, _defaults } inlist private do
163-
add_definition(pid, kind, tuple)
164-
end
165-
166-
# Process all unused
167161
reachable = reachable(pid)
168162
:lists.foldl(collect_unused_locals(&1, &2, reachable), [], private)
169163
end

lib/elixir/src/elixir_def.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ store_definition(Kind, Line, _CheckClauses, nil, _Name, _Args, _Guards, _Body, #
114114

115115
store_definition(Kind, Line, CheckClauses, Module, Name, Args, Guards, Body, #elixir_scope{} = DS) ->
116116
Arity = length(Args),
117-
S = DS#elixir_scope{module=Module, function={Name,Arity}, function_kind=Kind},
117+
Tuple = { Name, Arity },
118+
S = DS#elixir_scope{module=Module, function=Tuple},
119+
elixir_tracker:record_definition(Tuple, Kind, Module),
118120

119121
CO = elixir_compiler:get_opts(),
120122
Location = retrieve_file(Line, Module, S, CO),

lib/elixir/src/elixir_scope.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ build_ex_var(Line, Key, Name, S) when is_integer(Line) ->
7676
% Handle Macro.Env conversion
7777

7878
to_erl_env({ 'Elixir.Macro.Env', Module, File, _Line, Function, Aliases, Context,
79-
Requires, Functions, Macros, FileModules, FunctionKind }) ->
79+
Requires, Functions, Macros, FileModules }) ->
8080
#elixir_scope{module=Module,file=File,
8181
function=Function,aliases=Aliases,context=Context,
8282
requires=Requires,macros=Macros,functions=Functions,
83-
context_modules=FileModules,function_kind=FunctionKind}.
83+
context_modules=FileModules}.
8484

8585
to_ex_env({ Line, #elixir_scope{module=Module,file=File,
8686
function=Function,aliases=Aliases,context=Context,
8787
requires=Requires,macros=Macros,functions=Functions,
88-
context_modules=FileModules,function_kind=FunctionKind} }) when is_integer(Line) ->
88+
context_modules=FileModules} }) when is_integer(Line) ->
8989
{ 'Elixir.Macro.Env', Module, File, Line, Function, Aliases,
90-
Context, Requires, Functions, Macros, FileModules, FunctionKind }.
90+
Context, Requires, Functions, Macros, FileModules }.
9191

9292
% Provides a tuple with only the scope information we want to serialize.
9393

lib/elixir/src/elixir_tracker.erl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-export([
55
setup/1, cleanup/1,
66
record_local/2, record_import/3,
7-
record_warn/4,
7+
record_warn/4, record_definition/3,
88
ensure_no_import_conflict/4, ensure_all_imports_used/3,
99
warn_unused_local/3, format_error/1
1010
]).
@@ -31,9 +31,8 @@ record_local(Tuple, Module) when is_atom(Module) ->
3131
end);
3232
record_local(Tuple, #elixir_scope{function=Function})
3333
when Function == nil; Function == Tuple -> false;
34-
record_local(Tuple, #elixir_scope{module=Module, function=Function, function_kind=Kind}) ->
34+
record_local(Tuple, #elixir_scope{module=Module, function=Function}) ->
3535
if_tracker(Module, fun(Pid) ->
36-
?tracker:add_definition(Pid, Kind, Function),
3736
?tracker:add_local(Pid, Function, Tuple),
3837
true
3938
end).
@@ -54,6 +53,12 @@ record_import(Tuple, Receiver, Module) ->
5453
error:badarg -> false
5554
end.
5655

56+
record_definition(Tuple, Kind, Module) ->
57+
if_tracker(Module, fun(Pid) ->
58+
?tracker:add_definition(Pid, Kind, Tuple),
59+
true
60+
end).
61+
5762
%% HELPERS
5863

5964
if_tracker(Module, Callback) ->

0 commit comments

Comments
 (0)