@@ -6022,7 +6022,7 @@ defmodule Kernel do
|
||||
@doc since: "1.14.0"
|
||||
defmacro dbg(code \\ quote(do: binding()), options \\ []) do
|
||||
{mod, fun, args} = Application.compile_env!(__CALLER__, :elixir, :dbg_callback)
|
||||
apply(mod, fun, [code, options, __CALLER__ | args])
|
||||
Macro.compile_apply(mod, fun, [code, options, __CALLER__ | args], __CALLER__)
|
||||
end
|
||||
|
||||
## Sigils
|
||||
|
||||
+13
-1
@@ -1758,6 +1758,18 @@ defmodule Macro do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Applies a `mod`, `function`, and `args` at compile-time in `caller`.
|
||||
|
||||
This is used when you want to programatically invoke a macro at
|
||||
compile-time.
|
||||
"""
|
||||
@doc since: "1.16.0"
|
||||
def compile_apply(mod, fun, args, caller) do
|
||||
:elixir_env.trace({:remote_macro, [], mod, fun, length(args)}, caller)
|
||||
Kernel.apply(mod, fun, args)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Receives an AST node and expands it once.
|
||||
|
||||
@@ -2322,7 +2334,7 @@ defmodule Macro do
|
||||
## Atom handling
|
||||
|
||||
@doc """
|
||||
Classifies a runtime `atom` based on its possible AST placement.
|
||||
Classifies an `atom` based on its possible AST placement.
|
||||
|
||||
It returns one of the following atoms:
|
||||
|
||||
|
||||
@@ -334,6 +334,31 @@ defmodule Kernel.LexicalTrackerTest do
|
||||
assert URI in runtime
|
||||
end
|
||||
|
||||
test "dbg adds a compile dependency" do
|
||||
{{compile, exports, runtime, _}, _binding} =
|
||||
Code.eval_string("""
|
||||
defmodule Kernel.LexicalTrackerTest.Dbg do
|
||||
def foo, do: dbg(:ok)
|
||||
Kernel.LexicalTracker.references(__ENV__.lexical_tracker)
|
||||
end |> elem(3)
|
||||
""")
|
||||
|
||||
assert Macro in compile
|
||||
refute Macro in exports
|
||||
refute Macro in runtime
|
||||
|
||||
{{compile, exports, runtime, _}, _binding} =
|
||||
Code.eval_string("""
|
||||
defmodule Kernel.LexicalTrackerTest.NoDbg do
|
||||
Kernel.LexicalTracker.references(__ENV__.lexical_tracker)
|
||||
end |> elem(3)
|
||||
""")
|
||||
|
||||
refute Macro in compile
|
||||
refute Macro in exports
|
||||
refute Macro in runtime
|
||||
end
|
||||
|
||||
test "imports adds an export dependency" do
|
||||
{{compile, exports, runtime, _}, _binding} =
|
||||
Code.eval_string("""
|
||||
|
||||
Reference in New Issue
Block a user