Ensure dbg module is a compile-time dependency

Related to #12892.
This commit is contained in:
José Valim
2023-08-28 13:30:46 +02:00
parent 9f984f82d2
commit bd454e286d
3 changed files with 39 additions and 2 deletions
+1 -1
View File
@@ -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
View File
@@ -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("""