Skip to content

Commit bb8761a

Browse files
committed
Properly track imported function calls in tracer
Closes #13878.
1 parent 78eb659 commit bb8761a

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

Diff for: lib/elixir/src/elixir_dispatch.erl

+3-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ do_expand_import(Result, Meta, Name, Arity, Module, E, Trace) ->
208208
{import, Receiver} ->
209209
case expand_require(true, Meta, Receiver, Name, Arity, E, Trace) of
210210
{macro, _, _} = Response -> Response;
211-
error -> {function, Receiver, Name}
211+
error ->
212+
Trace andalso elixir_env:trace({remote_function, Meta, Receiver, Name, Arity}, E),
213+
{function, Receiver, Name}
212214
end;
213215
false when Module == ?kernel ->
214216
case elixir_rewrite:inline(Module, Name, Arity) of

Diff for: lib/elixir/test/elixir/kernel/lexical_tracker_test.exs

+50
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,56 @@ defmodule Kernel.LexicalTrackerTest do
523523
refute URI in runtime
524524
end
525525

526+
test "imported functions from quote adds dependencies" do
527+
{{compile, exports, runtime, _}, _binding} =
528+
Code.eval_string("""
529+
defmodule Kernel.LexicalTrackerTest.QuotedFun do
530+
import URI
531+
532+
defmacro parse_root() do
533+
quote do
534+
parse("/")
535+
end
536+
end
537+
end
538+
539+
defmodule Kernel.LexicalTrackerTest.UsingQuotedFun do
540+
require Kernel.LexicalTrackerTest.QuotedFun, as: QF
541+
QF.parse_root()
542+
Kernel.LexicalTracker.references(__ENV__.lexical_tracker)
543+
end |> elem(3)
544+
""")
545+
546+
assert URI in compile
547+
refute URI in exports
548+
refute URI in runtime
549+
end
550+
551+
test "imported macro from quote adds dependencies" do
552+
{{compile, exports, runtime, _}, _binding} =
553+
Code.eval_string("""
554+
defmodule Kernel.LexicalTrackerTest.QuotedMacro do
555+
import Config
556+
557+
defmacro config_env() do
558+
quote do
559+
config_env()
560+
end
561+
end
562+
end
563+
564+
defmodule Kernel.LexicalTrackerTest.UsingQuotedMacro do
565+
require Kernel.LexicalTrackerTest.QuotedMacro, as: QM
566+
def fun(), do: QM.config_env()
567+
Kernel.LexicalTracker.references(__ENV__.lexical_tracker)
568+
end |> elem(3)
569+
""")
570+
571+
assert Config in compile
572+
refute Config in exports
573+
refute Config in runtime
574+
end
575+
526576
test "defimpl does not add dependencies on for only on impl" do
527577
{{compile, exports, runtime, _}, _binding} =
528578
Code.eval_string("""

0 commit comments

Comments
 (0)