Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emit macro won't be able to check a lot of modules #37

Open
hissssst opened this issue Aug 2, 2024 · 3 comments
Open

emit macro won't be able to check a lot of modules #37

hissssst opened this issue Aug 2, 2024 · 3 comments

Comments

@hissssst
Copy link

hissssst commented Aug 2, 2024

Code in Elixir is compiled asynchronously. Therefore, loading all modules in compile times is not possible (because most modules are not even compiled yet), so some invocation of emit macro will just fail, because they will relate to the event of the not-yet compiled module

@vereis
Copy link
Collaborator

vereis commented Aug 3, 2024

Hmm.. I'll try to reproduce this in our codebase! I admit at Vetspire we primarily rely on the @decorate and @decorate_all macros which don't need to bother doing any compile time checks because they define their own events.

Do you think some fix might be just adding a Code.ensure_compiled!/1 call to the emit/N macro? If I understand correctly this should cause module compilation to pause and await the ensure_compiled module is compiled and loaded no?

@hissssst
Copy link
Author

hissssst commented Aug 4, 2024

Do you think some fix might be just adding a Code.ensure_compiled!/1 call to the emit/N macro?

I don't think that it is possible to fix.

You can reproduce it in some setup like

defmodule First do
  use Sibyl

  @decorate trace()
  def first_function do
    emit(Second, :second_function)
  end
end

And in other module

defmodule Second do
  use Sybil

  @decorate trace()
  def second_function do
    emit(First, :first_function)
  end  
end

Some module will be compiled first, and some module will be compiled second, therefore some function will be unable to check if event exists and defined

@hissssst
Copy link
Author

hissssst commented Aug 4, 2024

Overall, this issue can't be fixed. So the best approach would be to disable event? check or make it a runtime check or find some other way to check for existing event (like defining them in config.exs or such)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants