Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-Werror being used always, not only on validate #9866

Closed
alt-romes opened this issue Apr 4, 2024 · 16 comments · Fixed by #9867
Closed

-Werror being used always, not only on validate #9866

alt-romes opened this issue Apr 4, 2024 · 16 comments · Fixed by #9867
Assignees
Labels
re: devx Improving the cabal developer experience (internal issue) type: bug

Comments

@alt-romes
Copy link
Collaborator

In 0876e18 there was a refactor of cabal projects which introduced the following "regression":

Previously, we would only compile with ghc-options: -Werror when using the cabal.project.validate{.libonly} projects.
After 0876e18, we always compile with ghc-options: -Werror.

I don't think in-tree builds should use -Werror. It is valuable as a validation tool when the MR has to be finished and be validated by CI, but I don't think that when iterating on a patch one should care about all warnings, and -Werror makes this unnecessarily painful.

cc @philderbeast

@philderbeast
Copy link
Collaborator

I'd add "-Wwarn=some-error" in the local project to defer dealing with those.

@alt-romes
Copy link
Collaborator Author

I'd add "-Wwarn=some-error" in the local project to defer dealing with those.

That doesn't seem reasonable. Erroring on a warning in a development build is an exception, not the norm. Having to manually edit the cabal file to ignore warnings doesn't seem like a good developer experience.

@alt-romes
Copy link
Collaborator Author

I don't imagine this is hard to fix. cabal.project.release still exists, so it should suffice to move -Werror from project-cabal/ghc-options.config there.

@philderbeast
Copy link
Collaborator

Are you talking about warnings you are introducing?

@alt-romes
Copy link
Collaborator Author

alt-romes commented Apr 4, 2024

I'm saying that -Werror cannot be used by default on all builds. Only on validate builds.

@Mikolaj Mikolaj added re: devx Improving the cabal developer experience (internal issue) and removed needs triage labels Apr 4, 2024
@Mikolaj
Copy link
Member

Mikolaj commented Apr 4, 2024

Are you talking about warnings you are introducing?

I think, Rodrigo is talking about warning instances introduced by the developer, but not necessarily coming from new warning flags introduced by the developer.

@philderbeast
Copy link
Collaborator

Sorry I'm going to drop out of this discussion for a bit, on the road in a snow storm!

@alt-romes alt-romes self-assigned this Apr 5, 2024
alt-romes added a commit to alt-romes/cabal that referenced this issue Apr 5, 2024
Reverts a change that made `-Werror` be applied when building in tree Cabal, even when just developing.
Puts `-Werror` back in the `cabal.project.validate` validation project.

Fixes haskell#9866
@philderbeast
Copy link
Collaborator

Having to manually edit the cabal file to ignore warnings doesn't seem like a good developer experience.

Ignoring warnings is worse, isn't it?

It bothered me that hackage-security was spamming our build logs with lots of warnings so I fixed those with haskell/hackage-security#306.

I find cabal build output lengthy and its warning easy to miss. I don't mind fixing warnings.

@geekosaur
Copy link
Collaborator

Perhaps a flag (e.g. -fdev) possibly in a common import would make sense? Then it could also be used for any other options you'd only want during development.

@alt-romes
Copy link
Collaborator Author

alt-romes commented Apr 6, 2024

Perhaps a flag (e.g. -fdev) possibly in a common import would make sense? Then it could also be used for any other options you'd only want during development.

I think it would be better not to introduce more configuration levers.

It sounds like Phil is worried that warnings get ignored. I'm not saying otherwise:

  • We can/should/already do validate CI with -Werror. So no commits with warnings get merged to master.
  • OTOH, we don't need -Werror while developing because it seriously harms iterating quickly on a patch.

This is solved by the mechanism we have used thus far of having a cabal.project.x for different occasions.
One such file is cabal.project.validate which is used in validate jobs. I've updated that one only to use -Werror, reverting the status quo of having -Werror in every project file.

@alt-romes
Copy link
Collaborator Author

This makes it really annoying to use traceShow while developing because you get an error with -Werror...

@philderbeast
Copy link
Collaborator

This makes it really annoying to use traceShow while developing because you get an error with -Werror...

@alt-romes I had a look at #9811. I did the same but with traceShowId and found these ways to silence the errors;

$ git diff
diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
index fe2e86d8c..b0d4b87c2 100644
--- a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
+++ b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
@@ -32,6 +32,7 @@ module Distribution.Client.ProjectConfig.Legacy
   , renderPackageLocationToken
   ) where

+import Distribution.Compat.Prelude (traceShowId)
 import Data.Coerce (coerce)
 import Distribution.Client.Compat.Prelude

@@ -268,7 +269,7 @@ parseProjectSkeleton cacheDir httpTransport verbosity projectDir source (Project
         let importLocPath = importLoc `consProjectConfigPath` source

         -- Once we canonicalize the import path, we can check for cyclical imports
-        normLocPath <- canonicalizeConfigPath projectDir importLocPath
+        normLocPath <- canonicalizeConfigPath projectDir $ traceShowId importLocPath

         debug verbosity $ "\nimport path, normalized\n=======================\n" ++ render (docProjectConfigPath normLocPath)
  • With a cabal.project.local;
$ cat cabal.project.local
program-options
  ghc-options:
    -Wwarn=unused-imports
    -Wwarn=deprecations
    
$ cabal build cabal-install:cabal
  • With command line, specific -Wwarn= options;
$ cabal build cabal-install:cabal --ghc-options="-Wwarn=unused-imports -Wwarn=deprecations"
  • With a command line global -Wwarn option;
$ cabal build cabal-install:cabal --ghc-options="-Wwarn"

@alt-romes
Copy link
Collaborator Author

I understand that you can turn specific errors back into warnings again, but that is beyond my point that -Werror is not a good default for development.

The change to use -Werror by default was not agreed upon by the cabal developers.

To make -Werror the default always there needs to be consensus among us and a clear proposal to introduce this change. However, the change slipped through inadvertently into master during the refactor of cabal projects 0876e18. Mistakes are fine, but we need to revert them if they are problematic.

@mpickering
Copy link
Collaborator

I agree with Rodrigo that -Werror by default during development is cumbersome to work with. It is common workflow to write code which contains errors to begin with and then clean up all the errors when the patch is ready to submit. Please can we revert this change.

@fendor
Copy link
Collaborator

fendor commented Apr 11, 2024

I think -Werror is not a good development default. The described workarounds are easy enough for experts, but newcomer contributors (which we would like to have in cabal) will have a hard time figuring them out. Adding them to a "getting started" page kind of adds noise, modifying sources just so you can develop just like you are used, especially in a project where "run the main" is often the default way to debug.

A -fdev flag has the same disadvantages imo. Not discoverable.

I think -Werror should be enabled in CI only, so we still never have warnings in HEAD, but a more approachable dev environment.

@fendor
Copy link
Collaborator

fendor commented Apr 11, 2024

Also, the -Werror change seems orthogonal to the original PR, as it is not mentioned in the PR description, nor the related issues (though, it is prominently mentioned in the commits).

If we want to change this default, there should be an issue where we can discuss the motivation and consequences in more detail.

I have merged #9867 for now, as it restores the status-quo and multiple people have been unexpectedly bitten by the changes. Myself included :D

erikd pushed a commit to erikd/cabal that referenced this issue Apr 22, 2024
Reverts a change that made `-Werror` be applied when building in tree Cabal, even when just developing.
Puts `-Werror` back in the `cabal.project.validate` validation project.

Fixes haskell#9866
mergify bot pushed a commit that referenced this issue May 16, 2024
Reverts a change that made `-Werror` be applied when building in tree Cabal, even when just developing.
Puts `-Werror` back in the `cabal.project.validate` validation project.

Fixes #9866

(cherry picked from commit 355b48c)
Mikolaj pushed a commit that referenced this issue May 16, 2024
Reverts a change that made `-Werror` be applied when building in tree Cabal, even when just developing.
Puts `-Werror` back in the `cabal.project.validate` validation project.

Fixes #9866

(cherry picked from commit 355b48c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
re: devx Improving the cabal developer experience (internal issue) type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants