fireproofsocks

fireproofsocks

Circular dependencies during compilation

This is a bit of a theoretical question – I was cleaning up some logic in my Phoenix router.ex and I noticed that I can’t reference public functions that are defined in the router because the module isn’t yet available. When I think about it, I guess that makes sense: the plug and other macros have to run in order for the module to compile, so any functions that the module has are not yet available when the macros are running. So I put some of my helper functions into a separate file.

But that got me thinking… is it possible to have circular dependencies when compiling? E.g. module A has macros that call functions in module B, but module B has macros that call functions in module A? = Deadlock? Is that possible?

Marked As Solved

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

It is not, and the compiler will provide a handy error message if you do this by accident:

== Compilation error in file lib/a.ex ==
** (CompileError)  deadlocked waiting on module B
    lib/a.ex:2: (module)
    (stdlib 3.11.2) erl_eval.erl:680: :erl_eval.do_apply/6

== Compilation error in file lib/b.ex ==
** (CompileError)  deadlocked waiting on module A
    lib/b.ex:2: (module)
    (stdlib 3.11.2) erl_eval.erl:680: :erl_eval.do_apply/6

Compilation failed because of a deadlock between files.
The following files depended on the following modules:

  lib/a.ex => B
  lib/b.ex => A

Ensure there are no compile-time dependencies between those files and that the modules they reference exist and are correctly named

Where:

# a.ex
defmodule A do
  B.foo()
end

# b.ex
defmodule B do
  A.foo()
end

Where Next?

Popular in Questions Top

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
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
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
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
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
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
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
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
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
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement