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

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
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
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
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
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
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

Other popular topics Top

chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39523 209
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement