Using a type defined in another module implies in compile-time dependency #5087

Closed
rranelli opened this Issue Aug 3, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@rranelli
Contributor

rranelli commented Aug 3, 2016

Environment

  • Elixir version (elixir -v): 1.3.2 & 1.2.6
  • Operating system: debian8 (jessie)

Current behavior

While debugging recompilation issues in my project I noticed that whenever we
add a reference to a type defined in another module in a typespec, the other
module is added as compile-time dependency.

For example, if we have something like this:

## type_a.ex
defmodule TypeA do
  @type t :: integer
end

## type_c.ex
defmodule TypeC do
  @type t :: integer
end

## type_b.ex
defmodule TypeB do
  @spec a() :: TypeA.t
  def a, do: ()

  @spec c() :: TypeC.t
  def c, do: ()
end

I will end up with the following dependency graph:

screenshot from 2016-08-03 13 55 08

This contributes to unnecessary re-compilation. Because of this, some "cycles"
appeared in my project and changing a particular file implied in the
recompilation of 200+ others. I ended up commenting all type declarations and
specs to workaround the issue.

I have been able to reproduce this behavior in both v1.3.2 and v1.2.6.

(I have created a repository to
exemplify the problem.)

Expected behavior

I have talked with @josevalim over IRC about this and it seems to him that this
behavior is a bug.

@josevalim

This comment has been minimized.

Show comment
Hide comment
@josevalim

josevalim Aug 3, 2016

Member

Thank you! We should fix this and backport it. :)

Member

josevalim commented Aug 3, 2016

Thank you! We should fix this and backport it. :)

@rranelli

This comment has been minimized.

Show comment
Hide comment
@rranelli

rranelli Aug 3, 2016

Contributor

If there is anything I can do to help, let me know 👍

Contributor

rranelli commented Aug 3, 2016

If there is anything I can do to help, let me know 👍

@ericentin

This comment has been minimized.

Show comment
Hide comment
@ericentin

ericentin Aug 3, 2016

Contributor

@josevalim are you still taking a look at this like you were this morning? Happy to work on this if you would prefer to do stuff on GenStage or whatever.

Contributor

ericentin commented Aug 3, 2016

@josevalim are you still taking a look at this like you were this morning? Happy to work on this if you would prefer to do stuff on GenStage or whatever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment