Inconsistencies in dune Warnings

I have my dune-workspace configured with

 (dev
  (flags
   (:standard -warn-error +A-26-27-K-58))

It seems like dune is caching module builds with warnings so subsequent rebuilds aren’t showing warnings i.e. warnings are only showing the first time dune build is run. Also warnings seem to be printing twice:

dune build @ocaml-index @src/fmt --auto-promote src --profile dev
File "src/haz3lcore/statics/MakeTerm.re", line 331, characters 6-9:
331 |   let foo = 8;
            ^^^
Warning 26 [unused-var]: unused variable foo.
File "src/haz3lcore/statics/MakeTerm.re", line 331, characters 6-9:
331 |   let foo = 8;
            ^^^
Warning 26 [unused-var]: unused variable foo.
File "_none_", line 1:                   
Warning 58 [no-cmx-file]: no cmx file was found in path for module Ezjs_idb, and its interface was not compiled with -opaque

I believe the first behaviour is intentional. Warnings are shown only on the first compile because it’s assumed the developer doesn’t want to be reminded constantly. If they did, they would set it as an error.

1 Like

I’m not sure if this is the right place to discuss it but that seems like an odd decision. Because if your in the process of fixing warnings the other ones disappear on you. In our project we changed them to warnings not because we don’t want to address them, but just because we don’t want to stop compilation of the project in their presence.

It’s especially bad if you’re using --watch and are consistently rerunning build.

As far as I know this is common practice in languages which have both errors and warnings. Eg it’s the same in Scala.

I would rather say that the reason for this behaviour is that Dune does not do anything specific with warnings: the are emitted by the compiler when it is invoked; and so in subsequent builds if a module does not need to be rebuilt, the compiler is not invoked again, and so the warnings are not emitted again.

The idea of Dune remembering the warnings that were emitted the last time a module was built and replaying them at each build was considered in the past, but it needs some collaboration from the compiler to be done cleanly, which is why progress has been slow (also, there does not seem to be a huge demand for this).

Cheers,
Nicolas

6 Likes

I’m not sure what’s needed here. It’s just a matter of logging the tools outputs and replaying them on rebuilds. My own build system does that without any collaboration from the compiler – works with any other tool too.

Personally I find it to be (only one of) an extremely confusing and annoying aspect of dune.

4 Likes

In interpreted languages I’m used to having a separate lint command to see warnings that I can incorporate into my workflow. I’m going to attempt to use the VS Code problems panel to track warnings for now with ocamllsp, but a compiler flag or explicit lint step would be nice.

Just a reminder that the dune people can’t really track these issues if no one reports them :wink:

2 Likes

There is Cache hits "hide" warnings · Issue #7460 · ocaml/dune · GitHub which I expect has the same root cause.

2 Likes

Nice. That links to warning 9 enabled by default in dev mode · Issue #8645 · ocaml/dune · GitHub which also discusses and tracks the warning replay issue. Please ‘like and subscribe’ to express your support for both if you want :slight_smile:

1 Like