> > This is come up from my discussion with Jason Alexon on Slack when he was trying to implement
https://github.com/axelson/priv_check which checks for function calls to the private (aka marked as `@doc false`) functions.
>
> My understanding is that you want to not warn on calls to private functions, as long as they are generated. If this is the case, the generated information is part of the metadata and the metadata is available in compilation tracers, which is what I would most likely use to trace all calls.
I do not see such information in compiler trace metadata
iex(3)> Code.compile_quoted(quote do
...(3)> defmodule Foo do
...(3)> require Logger
...(3)>
...(3)> def test do
...(3)> Logger.info("foo")
...(3)> end
...(3)> end
...(3)> end)
{:remote_macro, [required: true, context: Elixir, import: Kernel], Kernel,
:defmodule, 2}
{:remote_function, [], :elixir_module, :compile, 4}
{:remote_function, [], Kernel.LexicalTracker, :read_cache, 2}
{:remote_macro, [required: true, context: Elixir, import: Kernel], Kernel, :def,
2}
{:remote_function, [], :elixir_def, :store_definition, 5}
{:remote_function, [], :elixir_module, :read_cache, 2}
{:remote_function, [], :elixir_utils, :noop, 0}
{:remote_macro, [], Logger, :info, 1}
{:remote_function, [], Logger, :__should_log__, 2}
{:remote_function, [], Logger, :__do_log__, 4}
As you can see, there is no way to detect that `Logger.__should_log__/2` and `Logger.__do_log__/4` are called from generated context, and these functions are quite private.
The same goes for internal Elixir functions like `:elixir_module.compile/4` or `Kernel.LexicalTracker.read_cache/2`. Being able to check that these functions weren't called directly by user would make implementation of such tracer much easier.
--
Łukasz Niemier
luk...@niemier.pl