ianrumford
Code.get_docs returning nil - beam file does not exist
Hello all. I’d appreciate some input on this.
To explain consider these two modules ModuleA and ModuleB
defmodule ModuleA do
@doc "ModuleA fun1"
def fun1(x) do
x
end
end
defmodule ModuleB do
require ModuleA
:functions |> ModuleA.__info__ |> IO.inspect
ModuleA |> Code.get_docs(:all) |> IO.inspect
end
If both modules are being compiled together, the get_docs in ModuleB returns nil. Only if ModuleA has been compiled previously does the get_docs in ModuleB succeed.
The crux of my question is how do I wait during the compilation of ModuleB for the beam file for ModuleA to exist?
Thanks in advance.
btw I’m using 1.6.3
Most Liked
bbense
I don’t have time to dig into this right now, but one thing to keep in mind is that one way to think of Elixir is that it’s a scripting language for running a compiler. You can put valid Elixir code outside the module def and that code will run at compile time. Something awful like
case :code.where_is_file('Elixir.ModuleA.beam') do
:not_existing -> loop_some_how
_ -> true
end
defmodule ModuleB do
require ModuleA
:functions |> ModuleA.__info__ |> IO.inspect
ModuleA |> Code.get_docs(:all) |> IO.inspect
end
I doubt that will work, but something like that is the solution.
ianrumford
Hi,
Your time is appreciated ![]()
I’d already tried sleeping inside the defmodule but not outside. (Since the parallel compile works with files not modules, and there is only one module in the file, the inside/outside distinction is moot in this case?).
But I tried outside: I put a Process.sleep(:infinity) outside the defmodule in ModuleB, touched both .ex files and did a mix compile. As you’d expect the mix just hung.
While the mix was hanging, I had a look at ebin and looked for the beam file for ModuleA which was surely compiled by then. There was no file.
It suggests that the parallelcompiler only writes the beam files late in the compilation, after (all?) the spawned compiler processes have completed.
Which begs the question as to the use case for Code.get_docs i.e. when can you use it?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








