Compiler Deadlocks

Hi all,

I’ve been working on a labelling system and I have the following two modules, which result in a deadlock. Now I think I understand why, as they reference each other; I’m just curious what you would do different to make it work.

I’m currently thinking that a Label shouldn’t be aware of a List, but not entirely convinced about that.

NB: I’ve refrained from calling it a taxonomy system, as I only plan on Lists having one level of labels. Otherwise I’d simply have a Term which could contain Terms. I’m avoiding that for now.

defmodule List do
    def create(name) do
      %List{name: name}

    def add_label(label = %Label{) do
        [label] ++ labels

defmodule Label do
    def create(list = %List{}, name) do

I don’t think that would cause a deadlock, see this test case for instance. Do the modules also require or use each other?

No. No require or use. There are ‘@spec’ lines though, would that cause problems?

Do you really have a toplevel module called List? There’s already one in :elixir, you should rename that one.

Also, to be sure if it really is tied to the circular dependency or not, you can try to replace the pattern-matches on the struct by a generic catch-all match.

1 Like

If you want to really have fun then try redefining the module :lists. It is amazing how little works after this. :wink:


Is this in a single file? or is each module in its own file?

No, there is no List module. I was simplifying for the post :confused:

@benwilson512, both modules are defined in separate files.

Have you tested using the catch all match?

Can you probably provide a minified project which shows the problem? Also please make sure you are using latest version of elixir.