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

Fix warnings in hls-graph, enable pedantic in CI #4047

Merged
merged 12 commits into from
Feb 6, 2024

Conversation

jhrcek
Copy link
Collaborator

@jhrcek jhrcek commented Feb 4, 2024

No description provided.

@@ -5,7 +5,65 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}

module Development.IDE.Graph.Internal.Types where
module Development.IDE.Graph.Internal.Types
Copy link
Collaborator Author

@jhrcek jhrcek Feb 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why am I adding explicit export list to this module?
I'm aware it's internal. But it exposes UnsafeMkKey + also things like newKey which use global Map within IORef to issue new Keys.
If we can make the Key newtype opaque, it would be safe to add {-# COMPLETE Key #-} pragma to get rid of "incomplete pattern match" warnings, because the only way to create new Key values are through newKey smart constructor.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion, although it is a rather long export list.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could try to make it shorter by splitting off KeyMap and KeySet into separate modules.. How does that sound?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or Key I guess, if that's the thing you want to be opaque. I don't want to derail you too much from your warning-fixing quest, but both of those sound like sensible refactorings to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, moved Key + KeyMap + KeySet stuff (because they depend on the internals) to separate module and removed explicit export list from Types module.

@@ -70,7 +70,7 @@ jobs:
os: ${{ runner.os }}

- name: Build `hls-graph` with flags
run: cabal v2-build hls-graph --flags="embed-files stm-stats"
run: cabal v2-build hls-graph --flags="embed-files stm-stats pedantic"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be implied by the later build with pedantic?

Copy link
Collaborator Author

@jhrcek jhrcek Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, that's what I expected too (that when you change flags cabal rebuilds all the libraries affected).

But then how do you explain the fact that this flags job passes on master with all those warnings present?

Running these 3 cabal builds locally (after cabal clean) I see that modules from hls-graph are compiled in the first two and the third (cabal v2-build --flags="pedantic") seems to be using hls-graph compiled in the first 2 runs:

$ cabal v2-build --flags="pedantic"
...
In order, the following will be built (use -v for more details):
 - ghcide-2.6.0.0 (exe:ghcide-test-preprocessor) (configuration changed)
 - hls-graph-2.6.0.0 (lib) (configuration changed)
 - shake-bench-0.2.0.0 (lib) (first run)
...
Preprocessing executable 'ghcide-test-preprocessor' for ghcide-2.6.0.0..
Building executable 'ghcide-test-preprocessor' for ghcide-2.6.0.0..
Preprocessing library for hls-graph-2.6.0.0..
Building library for hls-graph-2.6.0.0..                                   <<-- the output suggests the individual modules are no longer compiled (it's probably using artifacts from previous 2 builds???
Preprocessing library for shake-bench-0.2.0.0..
Building library for shake-bench-0.2.0.0..

With the additional pedantic in this PR it breaks on master, whereas it passes after the warning fixes in this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird. I wonder if we could simplify this by setting up a cabal.project.local as for the test options and then just doing a simple cabal build all?

@@ -5,7 +5,65 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}

module Development.IDE.Graph.Internal.Types where
module Development.IDE.Graph.Internal.Types
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion, although it is a rather long export list.

run: cabal v2-build hls-graph --flags="embed-files stm-stats"

- name: Build `ghcide` with flags
run: cabal v2-build ghcide --flags="ghc-patched-unboxed-bytecode test-exe executable bench-exe ekg"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ghc-patched-unboxed-bytecode and bench-exe flags seem to be some historic leftovers - they don't exist in ghcide.cabal anymore, so I just removed them from here.

The idea behind using cabal configure is that we do only single cabal build with pedantic flags enabled for everything - and don't skip pedantic when building hls-graph and ghcide.

Also I guessed what is the purpose of this flags job and added some comments - shout if you don't agree with any of this.

{-# LANGUAGE ViewPatterns #-}

module Development.IDE.Graph.Internal.Key
( Key -- Opaque - don't expose constructor, use newKey to create
Copy link
Collaborator Author

@jhrcek jhrcek Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved all the stuff that needs Key internals into this module with explicit import list, so that we don't expose the UnsafeMkKey constructor and all the unsafePerformIO stuff is hidden as impl. detail of this module.
I ultimately did this so that I can mark Key pattern as COMPLETE and fix bunch of "incomplete pattern match" warnings.

@jhrcek jhrcek marked this pull request as ready for review February 6, 2024 10:17
@jhrcek
Copy link
Collaborator Author

jhrcek commented Feb 6, 2024

@michaelpj I did the changes you suggested

  1. use cabal configure to turn on pedantic flag for everything and only do single cabal build
  2. moved Keyrelated internals to separate module with explicit import list
  • did minimal changes to make the build pass with the newly enabled pedantic flags

so please re-review.

Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! just one nit

.github/workflows/flags.yml Outdated Show resolved Hide resolved
@michaelpj michaelpj merged commit 0047d13 into haskell:master Feb 6, 2024
39 checks passed
@jhrcek jhrcek deleted the jhrcek/pedantic-hls-graph branch February 12, 2024 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants