diff --git a/aoc-dev.cabal b/aoc-dev.cabal index 26728b0..4cca12e 100644 --- a/aoc-dev.cabal +++ b/aoc-dev.cabal @@ -1,11 +1,4 @@ -cabal-version: 1.12 - --- This file has been generated from package.yaml by hpack version 0.34.4. --- --- see: https://github.com/sol/hpack --- --- hash: caed1f3774882334941126e63efa05febf1972dc0df0ec4db89d88b0eea3ba5f - +cabal-version: 2.4 name: aoc-dev version: 0.1.0.0 synopsis: Development environment for Advent of Code challenges @@ -17,8 +10,8 @@ homepage: https://github.com/mstksg/advent-of-code-dev#readme bug-reports: https://github.com/mstksg/advent-of-code-dev/issues author: Justin Le maintainer: justin@jle.im -copyright: (c) Justin Le 2018 -license: BSD3 +copyright: (c) Justin Le 2021 +license: MIT license-file: LICENSE build-type: Simple extra-source-files: @@ -26,10 +19,100 @@ extra-source-files: CHANGELOG.md source-repository head - type: git - location: https://github.com/mstksg/advent-of-code-dev + type: git + location: https://github.com/mstksg/advent-of-code-dev.git + +common common-options + build-depends: advent-of-code-api >=0.2.7 + , aeson + , ansi-terminal + , base >=4.7 && <5 + , bytestring + , containers + , criterion + , data-default-class + , deepseq + , directory + , filepath + , finite-typelits + , haskeline + , haskell-names + , Cabal + , haskell-src-exts + , hpack + , megaparsec + , microlens-th + , mtl + , pandoc + , parser-combinators + , profunctors + , template-haskell + , text + , th-abstraction + , time + , transformers + , yaml + + ghc-options: -Wall + -Wcompat + -Widentities + -Wincomplete-uni-patterns + -Wincomplete-record-updates + -Wno-partial-type-signatures + if impl(ghc >= 8.0) + ghc-options: -Wredundant-constraints + if impl(ghc >= 8.2) + ghc-options: -fhide-source-paths + if impl(ghc >= 8.4) + ghc-options: -Wmissing-export-lists + -Wpartial-fields + if impl(ghc >= 8.8) + ghc-options: -Wmissing-deriving-strategies + + default-language: Haskell2010 + default-extensions: + AllowAmbiguousTypes + ApplicativeDo + BangPatterns + BlockArguments + DataKinds + DeriveFoldable + DeriveFunctor + DeriveGeneric + DeriveTraversable + DerivingStrategies + EmptyCase + FlexibleContexts + FlexibleInstances + FunctionalDependencies + GADTs + GeneralizedNewtypeDeriving + ImplicitParams + KindSignatures + LambdaCase + MonadComprehensions + MultiParamTypeClasses + MultiWayIf + NumDecimals + OverloadedLabels + PartialTypeSignatures + PatternGuards + PatternSynonyms + PolyKinds + RankNTypes + RecordWildCards + ScopedTypeVariables + StandaloneDeriving + TemplateHaskell + TupleSections + TypeApplications + TypeInType + TypeOperators + UndecidableInstances + ViewPatterns library + import: common-options exposed-modules: AOC AOC.Challenge @@ -72,123 +155,14 @@ library Paths_aoc_dev hs-source-dirs: src - default-extensions: - AllowAmbiguousTypes - ApplicativeDo - BangPatterns - BlockArguments - DataKinds - DeriveFoldable - DeriveFunctor - DeriveGeneric - DeriveTraversable - EmptyCase - FlexibleContexts - FlexibleInstances - FunctionalDependencies - GADTs - GeneralizedNewtypeDeriving - ImplicitParams - KindSignatures - LambdaCase - MonadComprehensions - MultiParamTypeClasses - MultiWayIf - NumDecimals - OverloadedLabels - PartialTypeSignatures - PatternGuards - PatternSynonyms - PolyKinds - RankNTypes - RecordWildCards - ScopedTypeVariables - StandaloneDeriving - TemplateHaskell - TupleSections - TypeApplications - TypeInType - TypeOperators - UndecidableInstances - ViewPatterns - ghc-options: -Wall -Wcompat -Wno-partial-type-signatures -Wredundant-constraints - build-depends: - advent-of-code-api >=0.2.7 - , aeson - , ansi-terminal - , base >=4.7 && <5 - , bytestring - , containers - , criterion - , data-default-class - , deepseq - , directory - , filepath - , finite-typelits - , haskeline - , haskell-names - , haskell-src-exts - , hpack - , megaparsec - , microlens-th - , mtl - , pandoc - , parser-combinators - , profunctors - , template-haskell - , text - , th-abstraction - , time - , transformers - , yaml - default-language: Haskell2010 + other-modules: + Paths_aoc_dev executable aoc-dev + import: common-options main-is: aoc.hs - other-modules: - Paths_aoc_dev hs-source-dirs: app - default-extensions: - AllowAmbiguousTypes - ApplicativeDo - BangPatterns - BlockArguments - DataKinds - DeriveFoldable - DeriveFunctor - DeriveGeneric - DeriveTraversable - EmptyCase - FlexibleContexts - FlexibleInstances - FunctionalDependencies - GADTs - GeneralizedNewtypeDeriving - ImplicitParams - KindSignatures - LambdaCase - MonadComprehensions - MultiParamTypeClasses - MultiWayIf - NumDecimals - OverloadedLabels - PartialTypeSignatures - PatternGuards - PatternSynonyms - PolyKinds - RankNTypes - RecordWildCards - ScopedTypeVariables - StandaloneDeriving - TemplateHaskell - TupleSections - TypeApplications - TypeInType - TypeOperators - UndecidableInstances - ViewPatterns - ghc-options: -Wall -Wcompat -Wno-partial-type-signatures -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N build-depends: ansi-terminal , aoc-dev @@ -200,54 +174,15 @@ executable aoc-dev , mtl , optparse-applicative default-language: Haskell2010 + ghc-options: -threaded -rtsopts -with-rtsopts=-N test-suite aoc-dev-test + import: common-options type: exitcode-stdio-1.0 main-is: Spec.hs - other-modules: - Paths_aoc_dev hs-source-dirs: test - default-extensions: - AllowAmbiguousTypes - ApplicativeDo - BangPatterns - BlockArguments - DataKinds - DeriveFoldable - DeriveFunctor - DeriveGeneric - DeriveTraversable - EmptyCase - FlexibleContexts - FlexibleInstances - FunctionalDependencies - GADTs - GeneralizedNewtypeDeriving - ImplicitParams - KindSignatures - LambdaCase - MonadComprehensions - MultiParamTypeClasses - MultiWayIf - NumDecimals - OverloadedLabels - PartialTypeSignatures - PatternGuards - PatternSynonyms - PolyKinds - RankNTypes - RecordWildCards - ScopedTypeVariables - StandaloneDeriving - TemplateHaskell - TupleSections - TypeApplications - TypeInType - TypeOperators - UndecidableInstances - ViewPatterns - ghc-options: -Wall -Wcompat -Wno-partial-type-signatures -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N + ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: ansi-terminal , aoc-dev @@ -258,52 +193,12 @@ test-suite aoc-dev-test benchmark aoc-dev-bench type: exitcode-stdio-1.0 main-is: Bench.hs - other-modules: - Paths_aoc_dev hs-source-dirs: bench - default-extensions: - AllowAmbiguousTypes - ApplicativeDo - BangPatterns - BlockArguments - DataKinds - DeriveFoldable - DeriveFunctor - DeriveGeneric - DeriveTraversable - EmptyCase - FlexibleContexts - FlexibleInstances - FunctionalDependencies - GADTs - GeneralizedNewtypeDeriving - ImplicitParams - KindSignatures - LambdaCase - MonadComprehensions - MultiParamTypeClasses - MultiWayIf - NumDecimals - OverloadedLabels - PartialTypeSignatures - PatternGuards - PatternSynonyms - PolyKinds - RankNTypes - RecordWildCards - ScopedTypeVariables - StandaloneDeriving - TemplateHaskell - TupleSections - TypeApplications - TypeInType - TypeOperators - UndecidableInstances - ViewPatterns - ghc-options: -Wall -Wcompat -Wno-partial-type-signatures -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N -O2 + ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: aoc-dev , base >=4.7 && <5 , mtl default-language: Haskell2010 + diff --git a/app/aoc.hs b/app/aoc.hs index 19af029..c3d87a9 100644 --- a/app/aoc.hs +++ b/app/aoc.hs @@ -10,13 +10,13 @@ import Control.Monad.Except import Data.Char import Data.Foldable import Data.IORef -import Data.List import Data.Maybe import Lens.Micro import Options.Applicative import System.IO.Error import Text.Printf import Text.Read +import qualified Data.List as L import qualified Data.Map as M import qualified System.Console.ANSI as ANSI @@ -36,7 +36,7 @@ main = do <> header "aoc-dev - Advent of Code interactive development environment" <> progDesc ("Run, test, bench, challenges from Advent of Code, and view prompts. Available days: " ++ availableDays) ) - cfg@Cfg{..} <- configFile $ fromMaybe defConfPath _oConfig + cfg <- configFile $ fromMaybe defConfPath _oConfig out <- runExceptT $ case _oMode of MRun mro -> void $ mainRun cfg mro MView mvo -> void $ mainView cfg mvo @@ -46,7 +46,7 @@ main = do putStrLn "[ERROR]" mapM_ putStrLn e where - availableDays = intercalate ", " + availableDays = L.intercalate ", " . map (show . dayInt) . M.keys $ challengeMap diff --git a/src/AOC/Discover.hs b/src/AOC/Discover.hs index 9e4124f..5f42508 100644 --- a/src/AOC/Discover.hs +++ b/src/AOC/Discover.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE TemplateHaskell #-} -- | @@ -31,31 +32,37 @@ import AOC.Solver import Advent import Control.Applicative import Control.DeepSeq -import Language.Haskell.TH.Datatype import Control.Monad import Control.Monad.Trans.Class import Control.Monad.Trans.Maybe import Data.Bifunctor import Data.Data -import Data.Map (Map) +import Data.Foldable +import Data.Function +import Data.Map (Map) import Data.Maybe import Data.Traversable import Data.Void import GHC.Exts -import Language.Haskell.Exts as E +import Language.Haskell.Exts as E import Language.Haskell.Names -import Language.Haskell.TH as TH -import Language.Haskell.TH.Syntax (TExp(..)) +import Language.Haskell.TH as TH +import Language.Haskell.TH.Datatype +import Language.Haskell.TH.Syntax (TExp(..)) import Prelude import System.Directory import System.FilePath import Text.Printf -import qualified Data.List.NonEmpty as NE -import qualified Data.Map as M -import qualified Hpack.Config as H -import qualified Text.Megaparsec as P -import qualified Text.Megaparsec.Char as P -import qualified Text.Megaparsec.Char.Lexer as PL +import qualified Data.List.NonEmpty as NE +import qualified Distribution.Pretty as C +import qualified Data.Map as M +import qualified Distribution.PackageDescription as C +import qualified Distribution.PackageDescription.Parsec as C +import qualified Distribution.Simple.Utils as C +import qualified Distribution.Verbosity as C +import qualified Text.Megaparsec as P +import qualified Text.Megaparsec.Char as P +import qualified Text.Megaparsec.Char.Lexer as PL -- | Big quick escape hatch if things explode in the middle of solving. -- This will disable the check for NFData when using 'MkSomeSol' and assume @@ -69,7 +76,7 @@ checkIfNFData = True data ChallengeSpec = CS { _csDay :: Day , _csPart :: Part } - deriving (Show, Eq, Ord) + deriving stock (Show, Eq, Ord) -- | A map of days to parts to solutions. type ChallengeMap = Map Day (Map Part SomeSolution) @@ -100,8 +107,13 @@ type Parser = P.Parsec Void String -- a lower-case letter corresponding to the part of the challenge. -- -- See 'mkChallengeMap' for a description of usage. +#if MIN_VERSION_template_haskell(2,17,0) solutionList :: FilePath -> Code Q [(Day, (Part, SomeSolution))] solutionList dir = Code $ +#else +solutionList :: FilePath -> Q (TH.TExp [(Day, (Part, SomeSolution))]) +solutionList dir = +#endif fmap (TExp . ListE) . traverse (fmap unType . specExp) =<< runIO (getChallengeSpecs dir) @@ -126,16 +138,21 @@ specExp s@(CS d p) = do pure $ if isNF then 'MkSomeSolNF else 'MkSomeSolWH - pure $ TExp $ TupE - [ Just $ VarE 'mkDay_ `AppE` LitE (IntegerL (dayInt d)) - , Just $ TupE - [ Just $ ConE (partCon p) - , Just $ ConE con `AppE` VarE (mkName (specName s)) + pure $ TExp $ tTupE + [ VarE 'mkDay_ `AppE` LitE (IntegerL (dayInt d)) + , tTupE + [ ConE (partCon p) + , ConE con `AppE` VarE (mkName (specName s)) ] ] where partCon Part1 = 'Part1 partCon Part2 = 'Part2 +#if MIN_VERSION_template_haskell(2,16,0) + tTupE = TupE . fmap Just +#else + tTupE = TupE +#endif specName :: ChallengeSpec -> String specName (CS d p) = printf "day%02d%c" (dayInt d) (partChar p) @@ -159,9 +176,14 @@ getChallengeSpecs dir = do defaultExtensions :: IO [E.Extension] defaultExtensions = do - Right H.DecodeResult{..} <- H.readPackageConfig H.defaultDecodeOptions - Just H.Section{..} <- pure $ H.packageLibrary decodeResultPackage - pure $ parseExtension <$> sectionDefaultExtensions + gpd <- C.readGenericPackageDescription C.silent =<< C.defaultPackageDesc C.silent + pure . map reExtension . foldMap (C.defaultExtensions . C.libBuildInfo) $ gpdLibraries gpd + where + gpdLibraries gpd = + Data.Foldable.toList (C.library (C.packageDescription gpd)) + ++ foldMap Data.Foldable.toList (C.condLibrary gpd) + ++ foldMap (foldMap Data.Foldable.toList) (C.condSubLibraries gpd) + reExtension = parseExtension . C.prettyShow moduleSolutions :: (Data l, Eq l) => [Module l] -> [ChallengeSpec] moduleSolutions = (foldMap . foldMap) (maybeToList . isSolution) diff --git a/src/AOC/Run.hs b/src/AOC/Run.hs index 3dfd6a7..c75a4bc 100644 --- a/src/AOC/Run.hs +++ b/src/AOC/Run.hs @@ -63,7 +63,7 @@ import qualified System.Console.Haskeline as H data TestSpec = TSAll | TSDayAll { _tsDay :: Day } | TSDayPart { _tsSpec :: ChallengeSpec } - deriving Show + deriving stock Show -- | Options for 'mainRun'. data MainRunOpts = MRO { _mroSpec :: !TestSpec @@ -80,7 +80,7 @@ makeClassy ''MainRunOpts data MainViewOpts = MVO { _mvoSpec :: !TestSpec , _mvoWait :: !Bool } - deriving Show + deriving stock Show makeClassy ''MainViewOpts @@ -90,7 +90,7 @@ data MainSubmitOpts = MSO { _msoSpec :: !ChallengeSpec , _msoForce :: !Bool -- ^ Force submission even if bad? (Default: False) , _msoLock :: !Bool -- ^ Lock answer if submission succeeded? (Default: True) } - deriving Show + deriving stock Show makeClassy ''MainSubmitOpts diff --git a/src/AOC/Run/Config.hs b/src/AOC/Run/Config.hs index 07f35f8..bbe2a4c 100644 --- a/src/AOC/Run/Config.hs +++ b/src/AOC/Run/Config.hs @@ -32,7 +32,7 @@ data Config = Cfg { _cfgSession :: Maybe String -- ^ Default: 'Nothing' , _cfgYear :: Integer -- ^ Default: 2015 } - deriving (Generic) + deriving stock (Generic) -- | No session key, and 2015. instance Default Config where diff --git a/src/AOC/Run/Load.hs b/src/AOC/Run/Load.hs index 3a28389..e43bf89 100644 --- a/src/AOC/Run/Load.hs +++ b/src/AOC/Run/Load.hs @@ -70,7 +70,7 @@ data ChallengePaths = CP { _cpPrompt :: !FilePath , _cpTests :: !FilePath , _cpLog :: !FilePath } - deriving Show + deriving stock Show -- | A record of data (test inputs, answers) corresponding to a specific -- challenge. @@ -260,11 +260,11 @@ type Parser = MP.Parsec Void String data TestMeta = TM { _tmAnswer :: Maybe String , _tmData :: Map String Dynamic } - deriving Show + deriving stock Show data MetaLine = MLData String Dynamic | MLAnswer String - deriving Show + deriving stock Show parseTests :: Parser [(String, TestMeta)] diff --git a/src/AOC/Solver.hs b/src/AOC/Solver.hs index 9940e85..e7c585a 100644 --- a/src/AOC/Solver.hs +++ b/src/AOC/Solver.hs @@ -80,7 +80,7 @@ pattern MkSomeSol s <- (toHelp->SSH s) -- | Errors that might happen when running a ':~>' on some input. data SolutionError = SEParse | SESolve - deriving (Show, Eq, Ord, Generic) + deriving stock (Show, Eq, Ord, Generic) instance NFData SolutionError diff --git a/src/AOC/Util/DynoMap.hs b/src/AOC/Util/DynoMap.hs index 44a9855..2fd6011 100644 --- a/src/AOC/Util/DynoMap.hs +++ b/src/AOC/Util/DynoMap.hs @@ -11,7 +11,7 @@ import Data.Maybe import qualified Data.Map as M newtype DynoMap = Dyno { runDyno :: Map String Dynamic } - deriving (Semigroup, Monoid) + deriving newtype (Semigroup, Monoid) -- | Lookup the value at a given key in a 'Dyno'. --