dune icon indicating copy to clipboard operation
dune copied to clipboard

Some alerts come with no location and point to file `_none_`

Open Khady opened this issue 1 year ago • 1 comments

Expected Behavior

The ocaml_deprecated_auto_include warning doesn't seem to get attached to anything. It shows the source as File "_none_", line 1 which makes it troublesome to fix (I have to dig in _build/log to find which file was being compiled, as part of which lib/exe, then the dune file, ...). Ideally dune should give me those information directly.

Actual Behavior

$ dune build
File "_none_", line 1:                        
Alert ocaml_deprecated_auto_include: 
OCaml's lib directory layout changed in 5.0. The unix subdirectory has been
automatically added to the search path, but you should add -I +unix to the
command-line to silence this alert (e.g. by adding unix to the list of
libraries in your dune file, or adding use_unix to your _tags file for
ocamlbuild, or using -package unix for ocamlfind).

Reproduction

Build a binary or a lib which uses Unix or Str without putting the corresponding library dependency in the dune file.

Specifications

  • Version of dune (output of dune --version): ocaml_deprecated_auto_include
  • Version of ocaml (output of ocamlc --version): 5.2.0
  • Operating system (distribution and version): debian bookworm

Khady avatar Jul 29 '24 06:07 Khady

This alert is generated by the compiler; there isn't much Dune can do about it. It may be worth reporting it upstream over at https://github.com/ocaml/ocaml.

nojb avatar Jul 29 '24 06:07 nojb

Considering it is a problem from the compiler, should we close this issue?

maiste avatar Jul 22 '25 08:07 maiste

@maiste Let's make sure we have a repro case for the compiler and file an issue there first.

Alizter avatar Jul 22 '25 10:07 Alizter

OCaml issue here: https://github.com/ocaml/ocaml/issues/14163

Alizter avatar Jul 23 '25 01:07 Alizter

I've started an experiment in adding a better location ourselves https://github.com/ocaml/dune/pull/12076.

Alizter avatar Jul 25 '25 14:07 Alizter

We currently don't have a good way of attaching extra locations to compiler messages. Adding such a mechanism would probably be a lot of work and tricky to get right. It therefore seems like this particular issue won't be fixed any time soon.

For the record, you can get more information out of dune when you have an error message like this by passing --debug-dependency-path. This will also print a dependency trace of the issue which can be used to understand what exactly caused the issue. This is of course not a solution, but perhaps somewhat better than reading _build/log.

+|  File "_none_", line 1:
+|  Alert ocaml_deprecated_auto_include: 
+|  OCaml's lib directory layout changed in 5.0. The unix subdirectory has been
+|  automatically added to the search path, but you should add -I +unix to the
+|  command-line to silence this alert (e.g. by adding unix to the list of
+|  libraries in your dune file, or adding use_unix to your _tags file for
+|  ocamlbuild, or using -package unix for ocamlfind).
+|  
+|  File "foo.ml", line 1, characters 8-20:
+|  1 | let x = Unix.realdir ;;
+|              ^^^^^^^^^^^^
+|  Error: Unbound value Unix.realdir
+|  Hint: Did you mean readdir?
+|  -> required by _build/default/.foo.eobjs/native/dune__exe__Foo.cmx
+|  -> required by _build/default/foo.exe
+|  -> required by alias all
+|  -> required by alias default
+|  [1]

My experiment in #12076 allowed for the location to be attached, but I was not able to be selective about when it was attached. This meant that other compiler messages (with correct locations) were being enriched with rule locations, whereas we only want this particular alert to be enriched. However, if you are viewing the location via rpc as reported by ocamllsp for instance, you would get the rule location. Just not in the main dune build.

Alizter avatar Jul 27 '25 15:07 Alizter

Since this is hard to improve now on the dune side, I will have a look to see if the compiler can at least add the file name to this alert.

Octachron avatar Jul 31 '25 09:07 Octachron

The compiler will emit at least the file location in this deprecation alert starting with OCaml 5.5 (https://github.com/ocaml/ocaml/pull/14176).

Octachron avatar Aug 01 '25 15:08 Octachron

I will close this since the location has been improved upstream. It seems unlikely we will be able to improve this on the dune side without any major changes to how to deal with compiler messages.

Alizter avatar Aug 03 '25 16:08 Alizter