ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.63k stars 401 forks source link

Transitive dependencies take precedence over source modules #597

Closed timbertson closed 6 years ago

timbertson commented 6 years ago

I'm not very familiar with how ocaml handles module name clashes, but this doesn't seem right:

I upgraded a bunch of libraries after a period of inactivity (including jbuilder + jsoo + lwt), and now I get this compiler error:

File "src/www/password_form.ml", line 320, characters 41-57:
Error: Unbound value Selection.select

After a lot of guessing, I'm pretty sure it's using the Section module from compiler-libs. I eventually figure out this is a transitive dependency of js_of_ocaml.weak which my project does need, so there doesn't seem to be any way I can avoid the dependency.

I'm not quite sure whether the issue is:

  1. jbuilder should construct the sequence of -I flags so that my own selection.ml takes precedence over transitive dependencies (but will this actually work come link time?)
  2. compiler-libs shouldn't be exposing such a generic toplevel module name
  3. js_of_ocaml.weak shouldn't depend on compiler-libs (or I shouldn't be depending on js_of_ocaml.weak)
  4. there's no bug here, and I need to go pick another name and hope it doesn't clash with future modules :(
ghost commented 6 years ago

This looks like a bug indeed. The dependency from js_of_ocaml.weak to compiler-libs is a bit surprising, /cc @hhugo.

Are password_form.ml and selection.ml both part of the same library/executable stanza in src/www? I'm trying to figure out which -I needs to be moved

timbertson commented 6 years ago

Yep, they're both in https://github.com/timbertson/passe/tree/master/src/www - all these modules go into main.bc.js. The full compile command which failed is:

(brace yourself, I'm using opam2nix so there are a lot of long paths)

ocamlc src/www/password_form.{cmi,cmo,cmt} (exit 2)

(cd _build/default && /nix/store/8ackaq7vmg3mx7xv6410w850vf3xahvc-ocaml-4.05.0/bin/ocamlc.opt -w -40 -w @a-4-48-44-45-6-58-34 -g -bin-annot -I /nix/store/030wam2n70fvvwlmhx6b7akrwv0f6yw1-uri-1.9.6/lib/uri -I /nix/store/030wam2n70fvvwlmhx6b7akrwv0f6yw1-uri-1.9.6/lib/uri/services -I /nix/store/24x7nnch36y4sypn8qfll446d3r51w1l-sexplib-v0.10.0/lib/sexplib -I /nix/store/24x7nnch36y4sypn8qfll446d3r51w1l-sexplib-v0.10.0/lib/sexplib/0 -I /nix/store/2z03ac7zidvhdi2j7lv50dm70h4y131w-zed-1.6/lib/zed -I /nix/store/38rkqf33x84xn70b149la9aws82zyb33-ipaddr-2.8.0/lib/ipaddr -I /nix/store/38rkqf33x84xn70b149la9aws82zyb33-ipaddr-2.8.0/lib/ipaddr/unix -I /nix/store/3jwbascn3x743rxgn9726wfqqlfaz250-lwt-3.2.1/lib/lwt -I /nix/store/3w5g337wmaprrvvwmlw2j19rkw1mgjkx-easy-format-1.3.1/lib/easy-format -I /nix/store/3wwjxyn2i8ya16afr53jpf9gpnzcc14p-zarith-1.7/lib/zarith -I /nix/store/46k975ihzki4ra0ydk32qznryblzj31c-cohttp-lwt-unix-0.99.0/lib/cohttp-lwt-unix -I /nix/store/571zhykfj6c3mardj5c5ib8qpmvscy6p-logs-0.6.2/lib/logs -I /nix/store/6jqhhlkz4ypalnnhrw73mns7v90b26np-lwt_react-1.1.0/lib/lwt_react -I /nix/store/763cws0l3chx31r6blcb7gxszzhjgr62-conduit-lwt-1.0.3/lib/conduit-lwt -I /nix/store/7g1a9bb6vavlglii1mrmcbd3w01gbxp4-js_of_ocaml-ppx-3.0.2/lib/js_of_ocaml-ppx -I /nix/store/81fajh9qj217jqs81za3lnvx10bqb1sg-ocaml-migrate-parsetree-1.0.7/lib/ocaml-migrate-parsetree -I /nix/store/81gz3pvvk0gxw8543qx8fyvy1cwydx6b-camomile-0.8.7/lib/camomile -I /nix/store/8ackaq7vmg3mx7xv6410w850vf3xahvc-ocaml-4.05.0/lib/ocaml -I /nix/store/8ackaq7vmg3mx7xv6410w850vf3xahvc-ocaml-4.05.0/lib/ocaml/compiler-libs -I /nix/store/8ackaq7vmg3mx7xv6410w850vf3xahvc-ocaml-4.05.0/lib/ocaml/threads -I /nix/store/a6assk2r1adiwlg3ppyv40czyq9ch7cz-base-v0.10.0/lib/base -I /nix/store/a6assk2r1adiwlg3ppyv40czyq9ch7cz-base-v0.10.0/lib/base/caml -I /nix/store/a6assk2r1adiwlg3ppyv40czyq9ch7cz-base-v0.10.0/lib/base/shadow_stdlib -I /nix/store/a99j051rk78p97vw9imxffb6axc34cck-fieldslib-v0.10.0/lib/fieldslib -I /nix/store/b2dbk4qrspchbnjhr1lj5k8x0hrnk2f8-cstruct-3.2.1/lib/cstruct -I /nix/store/d76miij4mcm7p2lviy4qlmjdm23n95fr-vdoml-0.0.1/lib/vdoml -I /nix/store/djr6bp34rqpj71g7y706jwy4lqdnffyg-result-1.3/lib/result -I /nix/store/fjsaa9vgak9kfr5lncwlwn93ir6b02bi-ppx_tools_versioned-5.1/lib/ppx_tools_versioned -I /nix/store/giwr8ph4xkzijrbpzk4lqvck8vgksy2x-nocrypto-0.5.4/lib/nocrypto -I /nix/store/hhgsnzp10nfdz282lgrs1ixh2430xlqf-stringext-1.5.0/lib/stringext -I /nix/store/hjnrmhg1ih4ll05s8nb0gh7ngcjnlw6q-fmt-0.8.5/lib/fmt -I /nix/store/hmnjhlnrxrah2vx0f7gxy27yijwl3zyg-asn1-combinators-0.2.0/lib/asn1-combinators -I /nix/store/hwl04f1myqk58vdx8c1h2c7gk1bhjx5g-cohttp-lwt-0.99.0/lib/cohttp-lwt -I /nix/store/i1bw09vxxif7ppk47lhfw91dlwsy97fv-ptime-0.8.3/lib/ptime -I /nix/store/i1bw09vxxif7ppk47lhfw91dlwsy97fv-ptime-0.8.3/lib/ptime/os -I /nix/store/imybm8xbq68q0srv87v959cc0qqyqx0r-react-1.2.1/lib/react -I /nix/store/jrl09xm9sx1d31f3yg2rqmgxyw4104dd-x509-0.6.1/lib/x509 -I /nix/store/k7026wqd754fz7q8p2dn0yn42whr3n1s-uchar-0.0.2/lib/uchar -I /nix/store/kwdgn9j03njk77ragd2q3i2fg3n2qv7d-ocamlfind-1.7.3-1/lib/bytes -I /nix/store/ld1hm49im4al7x1mid5rcs74mj4pmc51-base64-2.2.0/lib/base64 -I /nix/store/mjpm5c2546x8aq8pnv4ni6zm4qqja34b-conduit-lwt-unix-1.0.3/lib/conduit-lwt-unix -I /nix/store/n16sy4bfwl6j83xnv59262xsd5dqnk2b-yojson-1.4.1/lib/yojson -I /nix/store/n2mkv7mc2iiknbs2pr4z7pkab50r8flm-js_of_ocaml-lwt-3.0.2/lib/js_of_ocaml-lwt -I /nix/store/p44dwj92rn7nmaq6fqm0qvkc2aw8d4qz-conduit-1.0.3/lib/conduit -I /nix/store/qba62fgy98sl0ijk0mfzg0j1861jxicr-biniou-1.2.0/lib/biniou -I /nix/store/qd27mbqacbd0jhlmzib3k6pcbg7fbc27-magic-mime-1.1.0/lib/magic-mime -I /nix/store/ql9zblppps2xqs9vai7d6lgcsffy5dxd-extlib-1.7.2/lib/extlib -I /nix/store/sc0cfv9d8l1dgpbshqn39vnwj67wa676-re-1.7.2/lib/re -I /nix/store/sc0cfv9d8l1dgpbshqn39vnwj67wa676-re-1.7.2/lib/re/emacs -I /nix/store/sc0cfv9d8l1dgpbshqn39vnwj67wa676-re-1.7.2/lib/re/posix -I /nix/store/sc0cfv9d8l1dgpbshqn39vnwj67wa676-re-1.7.2/lib/re/str -I /nix/store/vckzj5pffd7gi4wkqf01dqx9qfd7a3s3-astring-0.8.3/lib/astring -I /nix/store/vs1aafmlycm3mra1cbbrd1lgyh0zans5-js_of_ocaml-compiler-3.0.2/lib/js_of_ocaml-compiler -I /nix/store/vz65cmlkhbww0j2m9cl03nl3dcxaqzqm-lambda-term-1.12.0/lib/lambda-term -I /nix/store/wmdlbr1n5ahkw7ffhxa57zhw134q3b10-rresult-0.5.0/lib/rresult -I /nix/store/wri036dd4g5w9rg5ggjl0x2cdn9zhxj1-cstruct-lwt-3.2.1/lib/cstruct-lwt -I /nix/store/xggs4czsmb7v4alxw2wrg7gic7b044ii-cohttp-0.99.0/lib/cohttp -I /nix/store/xs1zpcr94kxjcz7djz2wr5lw866a6idp-tls-0.9.1/lib/tls -I /nix/store/xz1wnvsrrahvw7mbcfnimz5gfg4m56fk-js_of_ocaml-3.0.2/lib/js_of_ocaml -I src/client -I src/common -I src/unix -no-alias-deps -I src/www -o src/www/password_form.cmo -c -impl src/www/password_form.pp.ml)

File "src/www/password_form.ml", line 320, characters 41-57:
Error: Unbound value Selection.select

And FWIW:

$ ocamlfind query -r js_of_ocaml.weak
/nix/store/vs1aafmlycm3mra1cbbrd1lgyh0zans5-js_of_ocaml-compiler-3.0.2/lib/js_of_ocaml-compiler
/nix/store/xz1wnvsrrahvw7mbcfnimz5gfg4m56fk-js_of_ocaml-3.0.2/lib/js_of_ocaml
ghost commented 6 years ago

Ok, I wrote a fix.

BTW, even if the code builds, it's not guaranteed to link as unit names must be unique in OCaml. Though the error will probably be less cryptic that this one.