Skip to content

Add transitive dependencies section to Meta-programming anti-pattern #13766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/elixir/pages/mix-and-otp/introduction-to-mix.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ iex> recompile()

If anything had to be compiled, you see some informative text, and get the `:ok` atom back, otherwise the function is silent, and returns `:noop`.

To go further, check out [`mix compile.elixir`](https://hexdocs.pm/mix/Mix.Tasks.Compile.Elixir.html) documentation.

## Running tests

Mix also generated the appropriate structure for running our project tests. Mix projects usually follow the convention of having a `<filename>_test.exs` file in the `test` directory for each file in the `lib` directory. For this reason, we can already find a `test/kv_test.exs` corresponding to our `lib/kv.ex` file. It doesn't do much at this point:
Expand Down
4 changes: 3 additions & 1 deletion lib/mix/lib/mix/tasks/compile.elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ defmodule Mix.Tasks.Compile.Elixir do
Elixir is smart enough to recompile only files that have changed
and their dependencies. This means if `lib/a.ex` is invoking
a function defined over `lib/b.ex` at compile time, whenever
`lib/b.ex` changes, `lib/a.ex` is also recompiled.
`lib/b.ex` changes, `lib/a.ex` is also recompiled. More details
about dependencies between files can be found in the documentation
of [`mix xref`](`Mix.Tasks.Xref`).

Note Elixir considers a file as changed if its source file has
changed on disk since the last compilation AND its contents are
Expand Down
8 changes: 4 additions & 4 deletions lib/mix/lib/mix/tasks/xref.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Mix.Tasks.Xref do
touching one file in a project causes a large subset of the project
to recompile. The most common cause of these problems are the so-called
"compile-connected" files. Those are files you depend on at compile-time
(for example, by invoking its macro or using it in the body of amodule)
(for example, by invoking its macro or using it in the body of a module)
which also have their own dependencies.

Therefore, if your goal is to reduce recompilations, the first step is to run:
Expand Down Expand Up @@ -61,8 +61,8 @@ defmodule Mix.Tasks.Xref do
because compile time dependencies are transitive.

Having compile time dependencies is a common feature in Elixir projects.
However, the modules you depend on at compile-time must avoid runtime
dependencies within the same project. You can understand all of the
However, the modules you depend on at compile-time must avoid dependencies
to modules within the same project. You can understand all of the
dependencies of a given file by running:

$ mix xref trace lib/livebook_web.ex
Expand All @@ -75,7 +75,7 @@ defmodule Mix.Tasks.Xref do
Elixir tracks three types of dependencies between modules: compile,
exports, and runtime. If a module has a compile time dependency on
another module, the caller module has to be recompiled whenever the
callee changes (or any runtime dependency of the callee changes).
callee changes (or any dependency of the callee changes).
Let's see an example:

# lib/a.ex
Expand Down