> 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.

Those macros do not add generated: true to their quoted expression.
However, based on your examples, it seems you don't want something
necessarily related to the `generated: true` in quoted expressions (which
is why examples are important in said discussions!).

It seems what you want is something that says: "this came from a quote".
But keep in mind that, in general, it would be very hard to keep a list of
all quoted expressions nestings so far, because almost all macros mix
quoted code with unquoted code. The best we can do is to add some
annotation in the AST from `quote do...end`, but that will also lead to
false positives from macros that are building parts of the AST by hand.

On Tue, Sep 28, 2021 at 10:01 AM Łukasz Niemier <luk...@niemier.pl> wrote:

> > > 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
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elixir-lang-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/0C188167-01D6-4BE3-83DF-3147FDACEE30%40niemier.pl
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4L%3DRp%3DdSZXqt2%3DPKqxym3QvmvQ10956XoPWiTOWhkUWAw%40mail.gmail.com.

Reply via email to