Skip to content

Commit 699ba28

Browse files
committed
More docs
1 parent 4aace69 commit 699ba28

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

lib/mix/lib/mix/tasks/xref.ex

+34-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ defmodule Mix.Tasks.Xref do
3232
3333
Therefore, if your goal is to reduce recompilations, the first step is to run:
3434
35-
mix xref graph --format stats --label compile-connected
35+
$ mix xref graph --format stats --label compile-connected
3636
3737
This command will show general information about the project, but
3838
focus on compile-connected dependencies. In the stats, you will see
@@ -50,11 +50,11 @@ defmodule Mix.Tasks.Xref do
5050
that "lib/livebook_web.ex" itself has its own dependencies. We can find
5151
which files depend on "lib/livebook_web.ex" at compile time like this:
5252
53-
mix xref graph --sink lib/livebook_web.ex --label compile --only-nodes
53+
$ mix xref graph --sink lib/livebook_web.ex --label compile --only-nodes
5454
5555
And you can find the files lib/livebook_web.ex depends on like this:
5656
57-
mix xref graph --source lib/livebook_web.ex --only-nodes
57+
$ mix xref graph --source lib/livebook_web.ex --only-nodes
5858
5959
The trouble here is precisely that, if any of the files in the latter
6060
command changes, all of the files in the first command will be recompiled,
@@ -65,7 +65,7 @@ defmodule Mix.Tasks.Xref do
6565
dependencies within the same project. You can understand all of the
6666
dependencies of a given file by running:
6767
68-
mix xref trace lib/livebook_web.ex
68+
$ mix xref trace lib/livebook_web.ex
6969
7070
The command above will output three types of dependencies, which we
7171
detail next.
@@ -330,6 +330,36 @@ defmodule Mix.Tasks.Xref do
330330
command will list all files from all umbrella children, without
331331
any namespacing.
332332
333+
### Understanding the printed cycle
334+
335+
If you run `mix xref graph --format cycle`, Elixir will print cycles
336+
of shape:
337+
338+
Cycle of length 3:
339+
340+
lib/c.ex
341+
lib/b.ex
342+
lib/a.ex
343+
344+
The cycles are given in order: `c.ex` depends on `b.ex` which depends
345+
on `a.ex` which depends on `c.ex`. In particular, you want to avoid
346+
cycles with compile dependencies in there. You can find those cycles
347+
with:
348+
349+
$ mix xref graph --format cycles --label compile-connected
350+
351+
Which may look like this:
352+
353+
Cycle of length 3:
354+
355+
lib/c.ex
356+
lib/b.ex (compile)
357+
lib/a.ex
358+
359+
This means `c.ex` depends on `b.ex` at compile time. Any compile dependency
360+
in a cycle is by definition a compile-connected dependency, which must be
361+
generally avoided, as explained earlier in the module documentation.
362+
333363
## Shared options
334364
335365
Those options are shared across all modes:

0 commit comments

Comments
 (0)