[Proposal] @dependency_of

68 views
Skip to first unread message

Brian Cardarella

unread,
Feb 28, 2017, 3:55:47 AM2/28/17
to elixir-lang-core
I am doing some meta programming that has one module depending upon the state of another. However it isn't being picked up by the compiler that these two modules are related. And when the parent changes the child should be marked for recompilation. It would be really nice if we had a simple module attribute like: `@dependency_of` that took a list of modules. This could be incorporated into the manifest write out for determining dependencies. I assume at that point the compiler could work as normal.

José Valim

unread,
Feb 28, 2017, 3:58:01 AM2/28/17
to elixir-l...@googlegroups.com
"require OtherModule" should do it. If not, it is a bug in Mix or Elixir, so please provide a mechanism to reproduce it so we can fix it. :)



José Valim
Skype: jv.ptec
Founder and Director of R&D

On Tue, Feb 28, 2017 at 9:55 AM, Brian Cardarella <br...@dockyard.com> wrote:
I am doing some meta programming that has one module depending upon the state of another. However it isn't being picked up by the compiler that these two modules are related. And when the parent changes the child should be marked for recompilation. It would be really nice if we had a simple module attribute like: `@dependency_of` that took a list of modules. This could be incorporated into the manifest write out for determining dependencies. I assume at that point the compiler could work as normal.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/947a0dc2-20d0-4c45-8d45-eaaec3e60861%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

José Valim

unread,
Feb 28, 2017, 3:59:09 AM2/28/17
to elixir-l...@googlegroups.com
Actually, if you invoke the other module explicitly, it should also be enough to list it as a dependency and for Elixir/Mix to track it. Unless you are somehow generating those module names dynamically. Here is a good article on the topic: http://milhouseonsoftware.com/2016/08/11/understanding-elixir-recompilation/



José Valim
Skype: jv.ptec
Founder and Director of R&D

Brian Cardarella

unread,
Feb 28, 2017, 4:04:13 AM2/28/17
to elixir-lang-core, jose....@plataformatec.com.br
The problem is the compilation order. The relationship between mod A & B is being written in __before_compile__ for each module. mod A is using Module.put_attribute(B, :requires, A) in its __before_compile__ then B would do something like:

quote do
  for mod <- @requires, do: require mod
end

However B gets compiled before A and its @requires is always empty.


On Tuesday, February 28, 2017 at 3:59:09 AM UTC-5, José Valim wrote:
Actually, if you invoke the other module explicitly, it should also be enough to list it as a dependency and for Elixir/Mix to track it. Unless you are somehow generating those module names dynamically. Here is a good article on the topic: http://milhouseonsoftware.com/2016/08/11/understanding-elixir-recompilation/



José Valim
Skype: jv.ptec
Founder and Director of R&D

On Tue, Feb 28, 2017 at 9:57 AM, José Valim <jose....@plataformatec.com.br> wrote:
"require OtherModule" should do it. If not, it is a bug in Mix or Elixir, so please provide a mechanism to reproduce it so we can fix it. :)



José Valim
Skype: jv.ptec
Founder and Director of R&D
On Tue, Feb 28, 2017 at 9:55 AM, Brian Cardarella <br...@dockyard.com> wrote:
I am doing some meta programming that has one module depending upon the state of another. However it isn't being picked up by the compiler that these two modules are related. And when the parent changes the child should be marked for recompilation. It would be really nice if we had a simple module attribute like: `@dependency_of` that took a list of modules. This could be incorporated into the manifest write out for determining dependencies. I assume at that point the compiler could work as normal.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

Brian Cardarella

unread,
Feb 28, 2017, 4:13:38 AM2/28/17
to elixir-lang-core, jose....@plataformatec.com.br
Actually, I may have solve my problem by reversing everything. :p

José Valim

unread,
Feb 28, 2017, 4:15:02 AM2/28/17
to elixir-l...@googlegroups.com
I would recommend taking a step back. Injecting attributes from one module into the other is almost never going to work because the compiler happens in parallel. There is no guaranteed order of execution. B may not even be available unless you require it, which, as you said, means it will be compiled before A.

I would recommend reversing it if possible and have B explicitly require A.



José Valim
Skype: jv.ptec
Founder and Director of R&D

To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/6036391b-af14-4594-ae1c-c37b8aa2826a%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages