ianrumford

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

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

ianrumford

Hi,

Your time is appreciated :slight_smile:

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?

Where Next?

Popular in Questions Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
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
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
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
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
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
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

Other popular topics Top

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
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
New
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
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
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
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
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
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement