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

Support building with GHC 9.2 #1349

Merged
merged 7 commits into from
May 5, 2022
Merged

Support building with GHC 9.2 #1349

merged 7 commits into from
May 5, 2022

Conversation

RyanGlScott
Copy link
Contributor

This contains a variety of changes needed to make Cryptol compile with GHC 9.2:

  • In GHC 9.2, enabling UndecidableInstances no longer implies enabling FlexibleContexts (see here). As a result, I had to enable FlexibleContexts in Cryptol.ModuleSystem.Name.
  • The argo submodule was bumped to bring in the changes from Allow building with GHC 9.2 argo#191, which allows it to build with GHC 9.2.
  • The upper version bounds on base, bytestring, lens, base-compat, and sbv were raised to allow building them with GHC 9.2.

In addition, I fixed a variety of warnings that resulted from GHC 9.2 adding new things to -Wall, including -Woperator-whitespace-ext-confict, -Wnoncanonical-{monad,monoid}-instances, and -Wincomplete-uni-patterns. -Wincomplete-uni-patterns in particular was the trickiest to adapt to, and I have written a Note [-Wincomplete-uni-patterns and irrefutable patterns] describing the approach I took for irrefutable patterns.

@RyanGlScott RyanGlScott requested a review from yav May 2, 2022 12:16
cabal.project Outdated Show resolved Hide resolved
src/Cryptol/TypeCheck/TypePat.hs Show resolved Hide resolved
Copy link
Member

@yav yav left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

This contains a variety of changes needed to make Cryptol compile with GHC 9.2:

* In GHC 9.2, enabling `UndecidableInstances` no longer implies
  enabling `FlexibleContexts` (see
  [here](https://gitlab.haskell.org/ghc/ghc/-/wikis/migration/9.2?version_id=7e2ce63ba042c1934654c4316dc02028d8d3dd31#undecidableinstances-no-longer-implies-flexiblecontexts-in-instance-declarations)).
  As a result, I had to enable `FlexibleContexts` in
  `Cryptol.ModuleSystem.Name`.
* The `argo` submodule was bumped to bring in the changes from
  GaloisInc/argo#191, which allows it to build with GHC 9.2.
* The upper version bounds on `base`, `bytestring`, `lens`, `base-compat`, and
  `sbv` were raised to allow building them with GHC 9.2.
GHC 9.2 now includes `-Woperator-whitespace-ext-conflict` as a part of `-Wall`.
Thankfully, these warnings are simple to resolve: just put extra whitespace
after the affected uses of `$`.
GHC 9.2 adds `-Wnoncanonical-monad-instances` and
`-Wnoncanonical-monoid-instances` to `-Wall`, which warn whenever one has
explicit implementations of `return` or `mappend` that aren't simply
`return = pure` or `mappend = (<>)`. This patch makes sure that all `Monad`
and `Monoid` instances in Cryptol adhere to these conventions.
GHC 9.2 has a more aggressive pattern-match coverage checker than in previous
versions, which reveals that the `detailedPrompt` case of `mkPrompt` is
unreachable. This is technically true, as `detailedPrompt = False`, but it
would be nice if we didn't get a warning just for keeping this code around.
This simplest solution is to just change `detailedPrompt` to be `id False`,
which defeats the coverage checker.

An alternative would be to use `GHC.Exts`' newly added `considerAccessible`
function (see https://gitlab.haskell.org/ghc/ghc/-/merge_requests/5100), but
this would require CPP.
GHC 9.2 now includes `-Wincomplete-uni-patterns` as a part of `-Wall`. As a
result, building Cryptol with GHC 9.2 uncovers some previously undetected
warnings.

Some warnings can be fixed by rewriting the code slightly. For example,
changing a use of `Data.List.groupBy` to `Data.List.NonEmpty.groupBy` avoids
the need for an incomplete match on `(_ : _)` on the value that `groupBy`
returns. (Since `Data.List.NonEmpty` was added to `base` in `4.9`, this also
requires bumping the lower version bounds on `base` slightly.)

Other warnings were fixed by explicitly adding fall-through `error` cases.
The resulting code is no less partial than before, but it avoids warnings and
should provide a more specific error in the event that the fall-through cases
are reached.

Yet another class of warnings are those caused by the use of irrefutable
patterns, such as the definition of `ar1 ~[x] = x` in
`Cryptol.TypeCheck.TypePat`. It's rather unfortunate that
`-Wincomplete-uni-patterns` warns about these
(see https://gitlab.haskell.org/ghc/ghc/-/issues/14800), as the only way to
avoid the warning would be to rewrite these functions to use refutable
patterns, thereby changing their strictness properties. I've decided to simply
disable `-Wincomplete-uni-patterns` in each module that uses irrefutable
patterns to avoid this issue. I've written also written a Note explaining the
reasoning and referenced it in the affected modules.
@RyanGlScott RyanGlScott marked this pull request as ready for review May 5, 2022 00:09
@RyanGlScott RyanGlScott merged commit 5a2beda into master May 5, 2022
@RyanGlScott RyanGlScott deleted the ghc-9.2 branch May 5, 2022 00:10
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.

None yet

2 participants