From 19c1098f241695d4fe9c93d8504fb1991a677978 Mon Sep 17 00:00:00 2001 From: Robin Bate Boerop Date: Mon, 13 Apr 2026 12:21:15 -0700 Subject: [PATCH] test: document ocamldep behavior with transparent alias chains Transparent module aliases (e.g., `module M = OtherLib.Foo`) create cross-library .cmi reads that ocamldep does not report. This test documents the discrepancy: ocamldep only sees the direct library reference, but the compiler follows alias chains and reads .cmi files from transitive libraries at compile time. This property is critical for any future per-module inter-library dependency optimization (#4572). Signed-off-by: Robin Bate Boerop --- .../transparent-alias-chain.t | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/blackbox-tests/test-cases/per-module-lib-deps/transparent-alias-chain.t diff --git a/test/blackbox-tests/test-cases/per-module-lib-deps/transparent-alias-chain.t b/test/blackbox-tests/test-cases/per-module-lib-deps/transparent-alias-chain.t new file mode 100644 index 00000000000..cd2f03773f1 --- /dev/null +++ b/test/blackbox-tests/test-cases/per-module-lib-deps/transparent-alias-chain.t @@ -0,0 +1,65 @@ +Transparent module aliases create cross-library .cmi reads that ocamldep +does not report. This test documents the behavior: ocamldep only sees the +direct library reference, but the compiler follows alias chains and reads +.cmi files from transitive libraries at compile time. + +Any per-module inter-library dependency optimization must account for this. + + $ cat > dune-project < (lang dune 3.23) + > EOF + +Set up a chain: libA -> libB -> libC -> libD, where each intermediate +library creates a transparent alias to the next. + + $ mkdir libd + $ cat > libd/dune < (library (name libd)) + > EOF + $ cat > libd/leaf.ml < let v = 99 + > EOF + + $ mkdir libc + $ cat > libc/dune < (library (name libc) (libraries libd)) + > EOF + $ cat > libc/mid.ml < module L = Libd.Leaf + > EOF + + $ mkdir libb + $ cat > libb/dune < (library (name libb) (libraries libc)) + > EOF + $ cat > libb/bridge.ml < module M = Libc.Mid + > EOF + + $ mkdir liba + $ cat > liba/dune < (library (name liba) (libraries libb)) + > EOF + $ cat > liba/consumer.ml < let y = Libb.Bridge.M.L.v + > EOF + +ocamldep only reports the direct reference (Libb), not the transitive +libraries reached through aliases: + + $ ocamldep -modules liba/consumer.ml + liba/consumer.ml: Libb + +But the build succeeds because dune ensures all transitive library .cmi +files are available: + + $ dune build liba/.liba.objs/byte/liba__Consumer.cmo + +Verify that the compilation rule depends on .cmi files from all libraries +in the chain, not just the directly referenced one: + + $ dune rules liba/.liba.objs/byte/liba__Consumer.cmo 2>&1 | grep -o 'lib[a-d]\.' | sort -u + liba. + libb. + libc. + libd.