aboutsummaryrefslogtreecommitdiff
path: root/src/CHAD
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2025-11-10 22:31:56 +0100
committerTom Smeding <tom@tomsmeding.com>2025-11-10 22:31:56 +0100
commitcd135319f65f40a554d864b2a878a4ef44043a98 (patch)
treec51a5100b356ff4bf1a41a9b4b269faac3326850 /src/CHAD
parent57eb321eaeabc53c8c8b83d0554d8a8cca6eed76 (diff)
hlint cleanup
Diffstat (limited to 'src/CHAD')
-rw-r--r--src/CHAD/AST.hs4
-rw-r--r--src/CHAD/AST/Count.hs5
-rw-r--r--src/CHAD/AST/Pretty.hs5
-rw-r--r--src/CHAD/AST/Sparse.hs2
-rw-r--r--src/CHAD/AST/Weaken/Auto.hs3
-rw-r--r--src/CHAD/Compile.hs72
-rw-r--r--src/CHAD/Compile/Exec.hs1
-rw-r--r--src/CHAD/Drev.hs3
-rw-r--r--src/CHAD/Drev/Top.hs1
-rw-r--r--src/CHAD/ForwardAD.hs3
-rw-r--r--src/CHAD/ForwardAD/DualNumbers.hs5
-rw-r--r--src/CHAD/Interpreter.hs4
-rw-r--r--src/CHAD/Language.hs1
13 files changed, 42 insertions, 67 deletions
diff --git a/src/CHAD/AST.hs b/src/CHAD/AST.hs
index aa6aa96..2f4b5c2 100644
--- a/src/CHAD/AST.hs
+++ b/src/CHAD/AST.hs
@@ -1,7 +1,4 @@
{-# LANGUAGE DataKinds #-}
-{-# LANGUAGE DeriveFoldable #-}
-{-# LANGUAGE DeriveFunctor #-}
-{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
@@ -10,7 +7,6 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE QuantifiedConstraints #-}
-{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE StandaloneKindSignatures #-}
diff --git a/src/CHAD/AST/Count.hs b/src/CHAD/AST/Count.hs
index 133093a..46173d2 100644
--- a/src/CHAD/AST/Count.hs
+++ b/src/CHAD/AST/Count.hs
@@ -1,20 +1,17 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
-{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
-{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
-{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
-{-# LANGUAGE PatternSynonyms #-}
module CHAD.AST.Count where
import Data.Functor.Product
diff --git a/src/CHAD/AST/Pretty.hs b/src/CHAD/AST/Pretty.hs
index ea6ecba..9ddcb35 100644
--- a/src/CHAD/AST/Pretty.hs
+++ b/src/CHAD/AST/Pretty.hs
@@ -1,14 +1,10 @@
-{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
-{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TupleSections #-}
-{-# LANGUAGE TypeApplications #-}
-{-# LANGUAGE TypeOperators #-}
module CHAD.AST.Pretty (pprintExpr, ppExpr, ppSTy, ppSMTy, PrettyX(..)) where
import Control.Monad (ap)
@@ -523,4 +519,5 @@ render =
else renderString)
. layoutPretty LayoutOptions { layoutPageWidth = AvailablePerLine 120 1.0 }
where
+ {-# NOINLINE stdoutTTY #-}
stdoutTTY = unsafePerformIO $ hSupportsANSI stdout
diff --git a/src/CHAD/AST/Sparse.hs b/src/CHAD/AST/Sparse.hs
index 9156160..1cd5031 100644
--- a/src/CHAD/AST/Sparse.hs
+++ b/src/CHAD/AST/Sparse.hs
@@ -2,8 +2,6 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ImpredicativeTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
-{-# LANGUAGE StandaloneDeriving #-}
-{-# LANGUAGE RankNTypes #-}
{-# OPTIONS_GHC -fmax-pmcheck-models=80 #-}
module CHAD.AST.Sparse (module CHAD.AST.Sparse, module CHAD.AST.Sparse.Types) where
diff --git a/src/CHAD/AST/Weaken/Auto.hs b/src/CHAD/AST/Weaken/Auto.hs
index 14d8c59..229940b 100644
--- a/src/CHAD/AST/Weaken/Auto.hs
+++ b/src/CHAD/AST/Weaken/Auto.hs
@@ -1,13 +1,10 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
-{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
-{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
-{-# LANGUAGE TypeAbstractions #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
diff --git a/src/CHAD/Compile.hs b/src/CHAD/Compile.hs
index 38bef8c..44a335c 100644
--- a/src/CHAD/Compile.hs
+++ b/src/CHAD/Compile.hs
@@ -451,10 +451,10 @@ compileToString codeID env expr =
else id
,showString $ " const bool success = typed_kernel(" ++
"\n (" ++ repSTy (typeOf expr) ++ "*)(data + " ++ show result_offset ++ ")" ++
- concat (map (\((arg, typ), off) ->
- ",\n *(" ++ typ ++ "*)(data + " ++ show off ++ ")"
- ++ " /* " ++ arg ++ " */")
- (zip arg_pairs arg_offsets)) ++
+ concat (zipWith (\(arg, typ) off ->
+ ",\n *(" ++ typ ++ "*)(data + " ++ show off ++ ")"
+ ++ " /* " ++ arg ++ " */")
+ arg_pairs arg_offsets) ++
"\n );\n"
,showString $ " *(uint8_t*)(data + " ++ show okres_offset ++ ") = success;\n"
,if debugRefc then showString " fprintf(stderr, PRTAG \"Return\\n\");\n"
@@ -621,7 +621,7 @@ peekShape :: Ptr () -> Int -> SNat n -> IO (Shape n)
peekShape ptr off = \case
SZ -> return ShNil
SS n -> ShCons <$> peekShape ptr off n
- <*> (fromIntegral <$> peekByteOff @Int64 ptr (off + (fromSNat n) * 8))
+ <*> (fromIntegral <$> peekByteOff @Int64 ptr (off + fromSNat n * 8))
compile' :: SList (Const String) env -> Ex env t -> CompM CExpr
compile' env = \case
@@ -852,15 +852,15 @@ compile' env = \case
emit $ SLoop (repSTy tIx) ivar (CELit "0") (CELit shszname) $
pure (SVarDecl False (repSTy t) accvar (CELit x0name))
<> x0incrStmts -- we're copying x0 here
- <> (pure $ SLoop (repSTy tIx) jvar (CELit "0") (CELit lenname) $
- -- The combination function will consume the array element
- -- and the accumulator. The accumulator is replaced by
- -- what comes out of the function anyway, so that's
- -- fine, but we do need to increment the array element.
- arreltIncrStmts
- <> pure (SVarDecl True pairstrname pairvar (CEStruct pairstrname [("a", CELit accvar), ("b", CELit arreltlit)]))
- <> funStmts
- <> pure (SAsg accvar funres))
+ <> pure (SLoop (repSTy tIx) jvar (CELit "0") (CELit lenname) $
+ -- The combination function will consume the array element
+ -- and the accumulator. The accumulator is replaced by
+ -- what comes out of the function anyway, so that's
+ -- fine, but we do need to increment the array element.
+ arreltIncrStmts
+ <> pure (SVarDecl True pairstrname pairvar (CEStruct pairstrname [("a", CELit accvar), ("b", CELit arreltlit)]))
+ <> funStmts
+ <> pure (SAsg accvar funres))
<> pure (SAsg (resname ++ ".buf->xs[" ++ ivar ++ "]") (CELit accvar))
incrementVarAlways "foldx0" Decrement t x0name
@@ -1013,17 +1013,17 @@ compile' env = \case
emit $ SLoop (repSTy tIx) ivar (CELit "0") (CELit shsz1name) $
pure (SVarDecl False (repSTy t) accvar (CELit x0name))
<> x0incrStmts -- we're copying x0 here
- <> (pure $ SLoop (repSTy tIx) jvar (CELit "0") (CELit lenname) $
- -- The combination function will consume the array element
- -- and the accumulator. The accumulator is replaced by
- -- what comes out of the function anyway, so that's
- -- fine, but we do need to increment the array element.
- arreltIncrStmts
- <> pure (SVarDecl True pairstrname pairvar (CEStruct pairstrname [("a", CELit accvar), ("b", CELit arreltlit)]))
- <> funStmts
- <> pure (SVarDecl True (repSTy (typeOf efun)) funresvar funres)
- <> pure (SAsg accvar (CEProj (CELit funresvar) "a"))
- <> pure (SAsg (storesname ++ ".buf->xs[" ++ eltidx ++ "]") (CEProj (CELit funresvar) "b")))
+ <> pure (SLoop (repSTy tIx) jvar (CELit "0") (CELit lenname) $
+ -- The combination function will consume the array element
+ -- and the accumulator. The accumulator is replaced by
+ -- what comes out of the function anyway, so that's
+ -- fine, but we do need to increment the array element.
+ arreltIncrStmts
+ <> pure (SVarDecl True pairstrname pairvar (CEStruct pairstrname [("a", CELit accvar), ("b", CELit arreltlit)]))
+ <> funStmts
+ <> pure (SVarDecl True (repSTy (typeOf efun)) funresvar funres)
+ <> pure (SAsg accvar (CEProj (CELit funresvar) "a"))
+ <> pure (SAsg (storesname ++ ".buf->xs[" ++ eltidx ++ "]") (CEProj (CELit funresvar) "b")))
<> pure (SAsg (resname ++ ".buf->xs[" ++ ivar ++ "]") (CELit accvar))
incrementVarAlways "foldd1x0" Decrement t x0name
@@ -1071,16 +1071,16 @@ compile' env = \case
-- we need to loop in reverse here, but we let jvar run in the
-- forward direction so that we can use SLoop. Note jvar is
-- reversed in eltidx above
- <> (pure $ SLoop (repSTy tIx) jvar (CELit "0") (CELit lenname) $
- -- The combination function will consume the accumulator
- -- and the stores element. The accumulator is replaced by
- -- what comes out of the function anyway, so that's
- -- fine, but we do need to increment the stores element.
- storeseltIncrStmts
- <> funStmts
- <> pure (SVarDecl True (repSTy (typeOf efun)) funresvar funres)
- <> pure (SAsg accvar (CEProj (CELit funresvar) "a"))
- <> pure (SAsg (outctgname ++ ".buf->xs[" ++ eltidx ++ "]") (CEProj (CELit funresvar) "b")))
+ <> pure (SLoop (repSTy tIx) jvar (CELit "0") (CELit lenname) $
+ -- The combination function will consume the accumulator
+ -- and the stores element. The accumulator is replaced by
+ -- what comes out of the function anyway, so that's
+ -- fine, but we do need to increment the stores element.
+ storeseltIncrStmts
+ <> funStmts
+ <> pure (SVarDecl True (repSTy (typeOf efun)) funresvar funres)
+ <> pure (SAsg accvar (CEProj (CELit funresvar) "a"))
+ <> pure (SAsg (outctgname ++ ".buf->xs[" ++ eltidx ++ "]") (CEProj (CELit funresvar) "b")))
<> pure (SAsg (x0ctgname ++ ".buf->xs[" ++ ivar ++ "]") (CELit accvar))
incrementVarAlways "foldd2stores" Decrement (STArr (SS n) bty) storesname
@@ -1170,7 +1170,7 @@ compile' env = \case
accname <- genName' "accum"
emit $ SVarDecl False actyname accname
(CEStruct actyname [("buf", CECall "malloc_instr" [CELit (show (sizeofSTy (fromSMTy t)))])])
- emit $ SAsg (accname++".buf->ac") (maybe (CELit name1) id mcopy)
+ emit $ SAsg (accname++".buf->ac") (fromMaybe (CELit name1) mcopy)
emit $ SVerbatim $ "// initial accumulator constructed (" ++ name1 ++ ")."
e2' <- compile' (Const accname `SCons` env) e2
diff --git a/src/CHAD/Compile/Exec.hs b/src/CHAD/Compile/Exec.hs
index 5b4afc8..ffe5661 100644
--- a/src/CHAD/Compile/Exec.hs
+++ b/src/CHAD/Compile/Exec.hs
@@ -1,5 +1,4 @@
{-# LANGUAGE LambdaCase #-}
-{-# LANGUAGE TupleSections #-}
module CHAD.Compile.Exec (
KernelLib,
buildKernel,
diff --git a/src/CHAD/Drev.hs b/src/CHAD/Drev.hs
index 27dc6dd..bfa964b 100644
--- a/src/CHAD/Drev.hs
+++ b/src/CHAD/Drev.hs
@@ -7,11 +7,8 @@
{-# LANGUAGE ImpredicativeTypes #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE PolyKinds #-}
-{-# LANGUAGE QuantifiedConstraints #-}
-{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
-{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeData #-}
{-# LANGUAGE TypeFamilies #-}
diff --git a/src/CHAD/Drev/Top.hs b/src/CHAD/Drev/Top.hs
index b4e0cbe..65b4dee 100644
--- a/src/CHAD/Drev/Top.hs
+++ b/src/CHAD/Drev/Top.hs
@@ -1,7 +1,6 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE ImportQualifiedPost #-}
-{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
diff --git a/src/CHAD/ForwardAD.hs b/src/CHAD/ForwardAD.hs
index 7126e10..0ebc244 100644
--- a/src/CHAD/ForwardAD.hs
+++ b/src/CHAD/ForwardAD.hs
@@ -7,6 +7,7 @@
module CHAD.ForwardAD where
import Data.Bifunctor (bimap)
+import Data.Foldable (fold)
import System.IO.Unsafe
-- import Debug.Trace
@@ -89,7 +90,7 @@ tanScalars (STLEither a _) (Just (Left x)) = tanScalars a x
tanScalars (STLEither _ b) (Just (Right y)) = tanScalars b y
tanScalars (STMaybe _) Nothing = []
tanScalars (STMaybe t) (Just x) = tanScalars t x
-tanScalars (STArr _ t) x = foldMap id $ arrayMap (tanScalars t) x
+tanScalars (STArr _ t) x = fold $ arrayMap (tanScalars t) x
tanScalars (STScal STI32) _ = []
tanScalars (STScal STI64) _ = []
tanScalars (STScal STF32) x = [realToFrac x]
diff --git a/src/CHAD/ForwardAD/DualNumbers.hs b/src/CHAD/ForwardAD/DualNumbers.hs
index a71efc8..540ec2b 100644
--- a/src/CHAD/ForwardAD/DualNumbers.hs
+++ b/src/CHAD/ForwardAD/DualNumbers.hs
@@ -1,11 +1,10 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
-{-# LANGUAGE TypeApplications #-}
-{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
-- I want to bring various type variables in scope using type annotations in
@@ -157,7 +156,7 @@ dfwdDN = \case
EFold1Inner _ cm a b c -> EFold1Inner ext cm (dfwdDN a) (dfwdDN b) (dfwdDN c)
ESum1Inner _ e ->
let STArr n (STScal t) = typeOf e
- pairty = (STPair (STScal t) (STScal t))
+ pairty = STPair (STScal t) (STScal t)
in scalTyCase t
(ELet ext (dfwdDN e) $
ezip (ESum1Inner ext (emap (EFst ext (EVar ext pairty IZ))
diff --git a/src/CHAD/Interpreter.hs b/src/CHAD/Interpreter.hs
index 22ba2a4..6410b5b 100644
--- a/src/CHAD/Interpreter.hs
+++ b/src/CHAD/Interpreter.hs
@@ -6,13 +6,9 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE ImportQualifiedPost #-}
-{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
-{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
-{-# LANGUAGE ScopedTypeVariables #-}
-{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module CHAD.Interpreter (
diff --git a/src/CHAD/Language.hs b/src/CHAD/Language.hs
index 6dc91a5..ef89284 100644
--- a/src/CHAD/Language.hs
+++ b/src/CHAD/Language.hs
@@ -1,5 +1,4 @@
{-# LANGUAGE DataKinds #-}
-{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}