axelson

axelson

Scenic Core Team

Is it possible to use compiler tracing to detect when a function is called from generated code?

I’m working on a library that uses compiler tracing to detect calls to @moduledoc false and @doc false modules/functions. But if code was generated in a macro within a dependency I do not want to generate a warning for that call/reference even if that code is calling a module that would typically be private.

Here is an example of a macro that creates a function that calls a module (ExampleDep.Private) that is @moduledoc false but should not generate a warning from your application (PrivCheckExample):

defmodule ExampleDep.PubMacros do
  ...
  defmacro expand_funcs do
    quote location: :keep, unquote: false do
      def good_func do
        ExampleDep.Private.add(1, 2)
      end
    end
  end
  ...
end

I’m trying to disambiguate the :alias_reference check first. Here is all the data that I am receiving:

ref: {:alias_reference, [line: 13, counter: {PrivCheckExample, 3}, alias: false],
 ExampleDep.Private}
env: #Macro.Env<
  aliases: [],
  context: nil,
  context_modules: [PrivCheckExample],
  file: "lib/example_dep/pub_macros.ex",
  function: {:good_func, 0},
  functions: [{Kernel, [!=: 2, !==: 2, *: 2, ...]}],
  lexical_tracker: #PID<0.179.0>,
  line: 36,
  macro_aliases: [],
  macros: [{Kernel, ...}],
  module: PrivCheckExample,
  requires: [...],
  ...
>

Currently the only possibility that I see is that the file path in the Macro.Env is relative rather absolute, and the file name doesn’t match the current module (but since the file name could be anything that is not reliable). Can I depend on the fact that the file path is not absolute to know that the call was generated within a macro?

Most Liked

josevalim

josevalim

Creator of Elixir

No, unfortunately that’s not possible today. The file path in Macro.Env doesn’t guarantee it either, as it only changes when using location: :keep.

Where Next?

Popular in Questions Top

ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement