Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
name: Use Foldable.forM_
- hint:
lhs: "pure ()"
note: "Use 'pass'"
rhs: pass
note: "Use 'stub'"
rhs: stub
- hint:
lhs: "return ()"
note: "Use 'pass'"
rhs: pass
note: "Use 'stub'"
rhs: stub
- hint:
lhs: "(: [])"
note: "Use `one`"
Expand Down Expand Up @@ -2667,11 +2667,32 @@
lhs: sum xs / length xs
note: "Use `average` from `Relude.Extra.Foldable`"
rhs: average xs

- hint:
lhs: "\\a -> (a, a)"
note: "Use `dup` from `Relude.Extra.Tuple`"
note: "Use `dup`"
rhs: dup

- warn:
lhs: "() <$ a"
rhs: void a

- hint:
lhs: "pass"
note: "Use 'stub'"
rhs: stub

- hint:
lhs: "bool mempty a b"
note: "Use `whenTrue`"
rhs: a `whenTrue` b

- hint:
lhs: "bool a mempty b"
note: "Use `whenFalse`"
rhs: a `whenFalse` b

- hint:
lhs: "maybe mempty a b"
note: "Use `whenJust`"
rhs: a `whenJust` b
1 change: 0 additions & 1 deletion benchmarks/ParserBench.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module ParserBench (benchmarks) where

import Nix.Utils
import Nix.Parser

import Criterion
Expand Down
12 changes: 7 additions & 5 deletions hnix.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ flag profiling

library
exposed-modules:
Prelude
Nix
Nix.Utils
Nix.Atoms
Nix.Builtins
Nix.Cache
Expand Down Expand Up @@ -383,7 +385,6 @@ library
Nix.Type.Env
Nix.Type.Infer
Nix.Type.Type
Nix.Utils
Nix.Utils.Fix1
Nix.Value
Nix.Value.Equal
Expand All @@ -392,13 +393,13 @@ library
Nix.XML
other-modules:
Paths_hnix
Nix.Unused
autogen-modules:
Paths_hnix
hs-source-dirs:
src
mixins:
base hiding (Prelude)
, relude (Relude as Prelude)
, relude
ghc-options:
-Wall
Expand Down Expand Up @@ -477,6 +478,7 @@ library
, DeriveLift
, FlexibleContexts
, FlexibleInstances
, ScopedTypeVariables
, StandaloneDeriving
, TypeApplications
, TypeSynonymInstances
Expand Down Expand Up @@ -532,7 +534,6 @@ executable hnix
, time
mixins:
base hiding (Prelude)
, relude (Relude as Prelude)
, relude
default-extensions:
OverloadedStrings
Expand All @@ -544,6 +545,7 @@ executable hnix
, DeriveLift
, FlexibleContexts
, FlexibleInstances
, ScopedTypeVariables
, StandaloneDeriving
, TypeApplications
, TypeSynonymInstances
Expand Down Expand Up @@ -579,7 +581,6 @@ test-suite hnix-tests
TestCommon
mixins:
base hiding (Prelude)
, relude (Relude as Prelude)
, relude
hs-source-dirs:
tests
Expand Down Expand Up @@ -623,6 +624,7 @@ test-suite hnix-tests
, DeriveLift
, FlexibleContexts
, FlexibleInstances
, ScopedTypeVariables
, StandaloneDeriving
, TypeApplications
, TypeSynonymInstances
Expand Down Expand Up @@ -650,7 +652,6 @@ benchmark hnix-benchmarks
benchmarks
mixins:
base hiding (Prelude)
, relude (Relude as Prelude)
, relude
ghc-options:
-Wall
Expand All @@ -676,6 +677,7 @@ benchmark hnix-benchmarks
, DeriveLift
, FlexibleContexts
, FlexibleInstances
, ScopedTypeVariables
, StandaloneDeriving
, TypeApplications
, TypeSynonymInstances
Expand Down
31 changes: 13 additions & 18 deletions main/Main.hs
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
{-# language MultiWayIf #-}
{-# language ScopedTypeVariables #-}
{-# language TypeFamilies #-}
{-# language RecordWildCards #-}

module Main ( main ) where

import Nix.Utils
import Relude as Prelude ( force )
import Control.Comonad ( extract )
import qualified Control.Exception as Exception
import GHC.Err ( errorWithoutStackTrace )
import Control.Monad.Free
import Control.Monad.Ref ( MonadRef(readRef) )
import Control.Monad.Catch
import System.IO ( hPutStrLn
, getContents
)
import System.IO ( hPutStrLn )
import qualified Data.HashMap.Lazy as M
import qualified Data.Map as Map
import Data.Maybe ( fromJust )
import qualified Data.String as String
import Data.Time
import qualified Data.Text.IO as Text
import Text.Show.Pretty ( ppShow )
Expand Down Expand Up @@ -56,14 +51,14 @@ main' opts@Options{..} = runWithBasicEffectsIO opts execContentsFilesOrRepl
execContentsFilesOrRepl :: StandardT (StdIdT IO) ()
execContentsFilesOrRepl =
fromMaybe
loadFromCLIFilePathList
loadFromCliFilePathList
( loadBinaryCacheFile <|>
loadLiteralExpression <|>
loadExpressionFromFile
)
where
-- | The base case: read expressions from the last CLI directive (@[FILE]@) listed on the command line.
loadFromCLIFilePathList =
loadFromCliFilePathList =
case filePaths of
[] -> runRepl
["-"] -> readExpressionFromStdin
Expand All @@ -83,10 +78,10 @@ main' opts@Options{..} = runWithBasicEffectsIO opts execContentsFilesOrRepl

-- | The `--read` option: load expression from a serialized file.
loadBinaryCacheFile =
(\binaryCacheFile ->
(\ (binaryCacheFile :: Path) ->
do
let file = replaceExtension binaryCacheFile "nixc"
processCLIOptions (Just $ coerce file) =<< liftIO (readCache $ coerce binaryCacheFile)
let file = coerce $ (replaceExtension . coerce) binaryCacheFile "nixc"
processCLIOptions (Just file) =<< liftIO (readCache binaryCacheFile)
) <$> readFrom

-- | The `--expr` option: read expression from the argument string
Expand All @@ -97,9 +92,9 @@ main' opts@Options{..} = runWithBasicEffectsIO opts execContentsFilesOrRepl
-- We can start use Text as in the base case, requires changing Path -> Text
-- But that is a gradual process:
-- https://github.com/haskell-nix/hnix/issues/912
(processSeveralFiles . (coerce <$>) . String.lines <=< liftIO) .
(processSeveralFiles . (coerce . toString <$>) . lines <=< liftIO) .
(\case
"-" -> getContents
"-" -> Text.getContents
_fp -> readFile _fp
) <$> fromFile

Expand All @@ -126,7 +121,7 @@ main' opts@Options{..} = runWithBasicEffectsIO opts execContentsFilesOrRepl
either
(\ err -> errorWithoutStackTrace $ "Type error: " <> ppShow err)
(\ ty -> liftIO $ putStrLn $ "Type of expression: " <>
ppShow (fromJust $ Map.lookup @VarName @[Scheme] "it" (coerce ty))
ppShow (maybeToMonoid $ Map.lookup @VarName @[Scheme] "it" $ coerce ty)
)
(HM.inferTop mempty [("it", stripAnnotation expr')])

Expand Down Expand Up @@ -159,7 +154,7 @@ main' opts@Options{..} = runWithBasicEffectsIO opts execContentsFilesOrRepl
| evaluate =
if
| tracing -> evaluateExprWithEvaluator nixTracingEvalExprLoc expr
| Just path <- reduce -> evaluateExprWithEvaluator (reduction (coerce path) . coerce) expr
| Just path <- reduce -> evaluateExprWithEvaluator (reduction path . coerce) expr
| null arg || null argstr -> evaluateExprWithEvaluator nixEvalExprLoc expr
| otherwise -> processResult printer <=< nixEvalExprLoc (coerce mpath) $ expr
| xml = fail "Rendering expression trees to XML is not yet implemented"
Expand Down Expand Up @@ -245,10 +240,10 @@ main' opts@Options{..} = runWithBasicEffectsIO opts execContentsFilesOrRepl
liftIO $ Text.putStrLn path
when descend $
maybe
pass
stub
(\case
NVSet _ s' -> go (path <> ".") s'
_ -> pass
_ -> stub
)
mv
)
Expand Down
Loading