Skip to content

Commit d34408b

Browse files
committed
test: observational baseline for an unreferenced transitive library dep
An intermediate library [libB] declares [(libraries libA)] but its own source does not reference any module of [libA]. The consumer [main] uses [libB] and so transitively gains [libA] in its compilation context. Today's compile rules carry a glob over every transitively-reached library's public-cmi directory, so editing any of [libA]'s modules re-invalidates [main]. The test records the current rebuild count. Adds a baseline that future per-module dependency tracking work (ocaml#4572) can promote to a smaller number when the over-invalidation is fixed. Reproducer originally from @nojb: ocaml#14116 (comment) Signed-off-by: Robin Bate Boerop <me@robinbb.com>
1 parent b95749e commit d34408b

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Baseline: an intermediate library [intermediate_lib] declares
2+
[(libraries dep_lib)] but its module does not actually reference
3+
any of [dep_lib]'s modules. The consumer [main] uses
4+
[intermediate_lib] and so transitively gains [dep_lib] in its
5+
compilation context.
6+
7+
Today every consumer module declares a glob over each transitively-
8+
reached library's public-cmi directory, so editing
9+
[unreferenced_dep.ml] (which no source file references) re-
10+
invalidates [Main]. The test records the current rebuild count of
11+
[Main] when [unreferenced_dep.ml] is touched.
12+
13+
This test is observational: a tighter dependency tracker that drops
14+
unreferenced libraries from compile rules' deps would lower the
15+
count.
16+
17+
$ cat > dune-project <<EOF
18+
> (lang dune 3.23)
19+
> EOF
20+
21+
$ cat > dune <<EOF
22+
> (library
23+
> (name dep_lib)
24+
> (wrapped false)
25+
> (modules unreferenced_dep referenced_dep))
26+
> (library
27+
> (name intermediate_lib)
28+
> (wrapped false)
29+
> (modules intermediate_module)
30+
> (libraries dep_lib))
31+
> (executable (name main) (modules main) (libraries intermediate_lib))
32+
> EOF
33+
34+
$ cat > unreferenced_dep.ml <<EOF
35+
> let x = 42
36+
> EOF
37+
$ cat > referenced_dep.ml <<EOF
38+
> let x = 43
39+
> EOF
40+
$ cat > intermediate_module.ml <<EOF
41+
> let x = 42
42+
> EOF
43+
$ cat > main.ml <<EOF
44+
> let _ = Intermediate_module.x
45+
> EOF
46+
47+
$ dune build @check
48+
49+
Edit [unreferenced_dep.ml]. Neither [main.ml] nor
50+
[intermediate_module.ml] references [Unreferenced_dep] or any
51+
other [dep_lib] module, so a tighter filter could leave [Main]
52+
untouched. Today [Main] is rebuilt:
53+
54+
$ echo > unreferenced_dep.ml
55+
$ dune build @check
56+
$ dune trace cat | jq -s 'include "dune"; [.[] | targetsMatchingFilter(test("dune__exe__Main"))] | length'
57+
2

0 commit comments

Comments
 (0)