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

[RFC] Support the latest versions of GHC #289

Closed
wants to merge 2 commits into from
Closed

Conversation

friedbrice
Copy link
Member

This is a tentative PR. I'd like to merge it, but I'm not adamant. This PR eliminates almost all CPP, closing #252. (Some CPP is kept around for gating certain tests by platform support.)

So, I'd like to tackle some of the Issues, such as #262, #258, and #272, and I would need to smooth out and simplify project maintenance before doing so.

I'd like to hear what thoughts @scotty-web/admins, @fumieval, @RyanGlScott, and other interested parties have about the following changes.

  • remove most CPP
  • use Cabal 3.0
  • add ghc 9.2, 9.4 to ci
  • drop ghc pre 8.10 from ci
  • move library files to src/
  • fourmolu and hlint
  • make copyright in license files agree with copyright in cabal files

* add ghc 9.2, 9.4 to ci
* make copyright in license files agree with copyright in cabal files
* move library files to src/
* fourmolu and hlint
* use Cabal 3.0
* remove most CPP
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE RecordWildCards #-}

module Web.Scotty.Internal.Types where
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to src/Web/Scotty/Internal/Types.hs

, GeneralizedNewtypeDeriving
#-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}

module Main (main) where
Copy link
Member Author

Choose a reason for hiding this comment

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

Code formatter/linter. No functional changes.

@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}

module Main (main) where
Copy link
Member Author

Choose a reason for hiding this comment

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

Code formatter/linter. No functional changes.

@@ -1,10 +1,11 @@
{-# LANGUAGE OverloadedStrings #-}

module Main (main) where
Copy link
Member Author

Choose a reason for hiding this comment

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

Code formatter/linter. No functional changes.

@@ -1,23 +1,24 @@
{-# LANGUAGE OverloadedStrings #-}

-- This examples requires you to: cabal install cookie
-- and: cabal install blaze-html
module Main (main) where
Copy link
Member Author

Choose a reason for hiding this comment

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

Code formatter/linter. No functional changes.

{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Main (main) where
Copy link
Member Author

Choose a reason for hiding this comment

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

Code formatter/linter. No functional changes.

@@ -1,4 +1,6 @@
{-# LANGUAGE OverloadedStrings, GeneralizedNewtypeDeriving #-}
Copy link
Member Author

Choose a reason for hiding this comment

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

Code formatter/linter. No functional changes.

@@ -1,15 +1,16 @@
{-# LANGUAGE OverloadedStrings #-}

module Main (main) where
Copy link
Member Author

Choose a reason for hiding this comment

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

Code formatter/linter. No functional changes.

@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}

module Main (main) where
Copy link
Member Author

Choose a reason for hiding this comment

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

Code formatter/linter. No functional changes.

@@ -10,30 +10,34 @@ module Main where
import Control.Monad.Reader (MonadIO, MonadReader, ReaderT, asks, lift, runReaderT)
Copy link
Member Author

Choose a reason for hiding this comment

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

Code formatter/linter. No functional changes.

Category: Web
Stability: experimental
Build-type: Simple
Cabal-version: >= 1.10
Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to Cabal 3.0

Build-type: Simple
Cabal-version: >= 1.10
Description: Example programs using @scotty@
tested-with: GHC == 7.6.3
Copy link
Member Author

Choose a reason for hiding this comment

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

added GHC 9.4, 9.2. Dropped GHC <8.10

location: https://github.com/scotty-web/scotty
subdir: examples

common examples-common
Copy link
Member Author

Choose a reason for hiding this comment

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

I put Scotty and GHC boot libs in a common build-depends. This adds some spurious build-depends to some of the examples, but I figure it's a moot point as there's not really going to be a Haskell distribution that doesn't include the GHC boot libs already.

@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}

module Main (main) where
Copy link
Member Author

Choose a reason for hiding this comment

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

Code formatter/linter. No functional changes.

@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}

module Main (main) where
Copy link
Member Author

Choose a reason for hiding this comment

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

Code formatter/linter. No functional changes.

Category: Web
Stability: experimental
Build-type: Simple
Cabal-version: >= 1.10
Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to Cabal 3.0

[WAI] <http://hackage.haskell.org/package/wai>
.
[Warp] <http://hackage.haskell.org/package/warp>
tested-with: GHC == 7.6.3
Copy link
Member Author

Choose a reason for hiding this comment

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

Add GHCs 9.4, 9.2. Drop GHCs <8.10

@@ -64,81 +63,87 @@ Extra-source-files:
examples/static/jquery-json.js
examples/uploads/.keep

Library
Copy link
Member Author

Choose a reason for hiding this comment

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

cosmetic refactor, to reduce future diff noise

Web.Scotty.Route
Web.Scotty.Util
default-language: Haskell2010
build-depends: aeson >= 0.6.2.1 && < 2.2,
Copy link
Member Author

@friedbrice friedbrice Nov 20, 2022

Choose a reason for hiding this comment

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

I'm kinda skeptical that these bounds really make a lot of sense. How were they calculated?

In the PR, I only bound base and leave the rest up to Cabal. To compensate for lack of bounds in the cabal file, I've included freeze files from some successful builds with a variety of GHCs. If people are adamant about it, I can use the feeze files to compute version bounds.

@@ -7,46 +6,99 @@
-- the comments on each of these functions for more information.
module Web.Scotty
Copy link
Member Author

Choose a reason for hiding this comment

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

Code formatter/linter. No functional change.

Comment on lines -78 to +75
(e,r) <- flip MS.runStateT def
$ flip runReaderT env
$ runExceptT
$ runAM
$ action `catchError` (defH h)
(e, r) <-
flip MS.runStateT def $
flip runReaderT env $
runExceptT $
runAM $
action `catchError` defH h
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't necessarily agree with the code formatter, but I think it's useful for reducing future diff noise. I'm open to rolling back the formatting changes if people disagree.

Comment on lines -267 to +279
parseParam t = if t' == T.toCaseFold "true"
then Right True
else if t' == T.toCaseFold "false"
then Right False
else Left "parseParam Bool: no parse"
where t' = T.toCaseFold t
parseParam t
| t' == true = Right True
| t' == false = Right False
| otherwise = Left "parseParam Bool: no parse"
where
t' = T.toCaseFold t
true = T.toCaseFold "true"
false = T.toCaseFold "false"
Copy link
Member Author

@friedbrice friedbrice Nov 20, 2022

Choose a reason for hiding this comment

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

I cleaned up this block by changing nested if/then to guards, and I factored out true and false so that a sufficiently-advanced compiler could float them if it wanted.

{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Web.Scotty.Route
Copy link
Member Author

@friedbrice friedbrice Nov 20, 2022

Choose a reason for hiding this comment

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

  • remove legacy CPP
  • Code formatter/linter.

@@ -11,84 +12,145 @@
-- the comments on each of these functions for more information.
module Web.Scotty.Trans
Copy link
Member Author

Choose a reason for hiding this comment

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

Code formatter/linter. No functional change.

@@ -12,19 +12,18 @@ module Web.Scotty.Util
, readRequestBody
Copy link
Member Author

Choose a reason for hiding this comment

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

Code formatter/linter. No functional change.

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}

module Web.Scotty.Action
Copy link
Member Author

Choose a reason for hiding this comment

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

  • Remove legacy CPP.
  • Code formatter/linter.

it "stops the execution of an action" $ do
get "/scotty" `shouldRespondWith` 400

-- Skip these tests on Windows, since Unix sockets are not available
#if !defined(mingw32_HOST_OS)
Copy link
Member Author

Choose a reason for hiding this comment

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

I moved some things that were top-level and nested them into the test block. Reads better with the CPP that way.

{-# LANGUAGE OverloadedStrings, CPP #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}

module Web.ScottySpec (main, spec) where
Copy link
Member Author

Choose a reason for hiding this comment

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

minor functional change by moving some helpers from top-level into a let bind. This looks like a huge diff, but set github to ignore whitespace, as the changes are mostly indentation.

Comment on lines +168 to +169
deriving newtype (Functor, Applicative, Monad, MonadIO)
deriving (Semigroup, Monoid) via (Ap (ActionT e m) a)
Copy link
Member Author

Choose a reason for hiding this comment

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

Deriving Semigroup, Monoid, and Monad.

Copy link
Collaborator

Choose a reason for hiding this comment

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

doesn't this rule out old GHCs? or are we dropping them (which is also fine)

Copy link
Collaborator

Choose a reason for hiding this comment

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

drop ghc pre 8.10 from ci

I suppose this is intentional

instance (Monad m, ScottyError e) => Fail.MonadFail (ActionT e m) where
fail = ActionT . throwError . stringError

instance (Monad m, ScottyError e) => Alternative (ActionT e m) where
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved implementations from MonadPlus instance to Alternative instance.

{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}

module Web.Scotty.Internal.Types where
Copy link
Member Author

Choose a reason for hiding this comment

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

  • moved from ./Web/Scotty/Internal/Types.hs.
  • remove CPP
  • derive (functionally compatible) instances instead of writing them

@fumieval
Copy link
Collaborator

It might be too late, but it would be nice to separate code style changes at least

@friedbrice
Copy link
Member Author

@fumieval good call. i can easily split them out :-)

@fumieval fumieval mentioned this pull request Jun 17, 2023
@ocramz
Copy link
Collaborator

ocramz commented Sep 10, 2023

good call. i can easily split them out :-)

Hi @friedbrice , would you be able to move this forward so we do one last review and merge? Thank you!

Copy link
Collaborator

@ocramz ocramz left a comment

Choose a reason for hiding this comment

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

Took me a while to review it all but eventually LGTM.

For the future let's not have formatting PRs mixed with code changes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@friedbrice is this file necessary?

license: BSD-3-Clause
license-file: LICENSE
author: Andrew Farmer <[email protected]>
maintainer: Daniel Brice <[email protected]>
Copy link
Collaborator

Choose a reason for hiding this comment

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

there are other maintainers too at present

Copy link
Collaborator

@ocramz ocramz left a comment

Choose a reason for hiding this comment

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

Apologies, I'm not able to fix the conflicts so I cannot merge these changes.

@ocramz
Copy link
Collaborator

ocramz commented Sep 23, 2023

Let's have separate PRs for linting and functional changes in the future.

@ocramz ocramz closed this Sep 23, 2023
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.

3 participants