Skip to content

Commit

Permalink
Merge #884 Parser: Result is synonim of Either; Thunk.Basic: nonblock…
Browse files Browse the repository at this point in the history
…ing queryM, internal changes to `force*`

  * [(link)](https://github.com/haskell-nix/hnix/pull/884/files) `Nix.Parser`: `Parser`: Data type was equivalent to `Either`, so became a type synonim for `Either`.

  * [(link)](https://github.com/haskell-nix/hnix/pull/884/files) `Nix.Thunk.Basic`: `instance MonadThunk (NThunkF m v) m v`: `queryM`: implementation no longer blocks the thunk resource it only reads from.
  • Loading branch information
Anton-Latukha authored Mar 15, 2021
2 parents 36802ae + c30b164 commit 4796681
Show file tree
Hide file tree
Showing 39 changed files with 1,227 additions and 963 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Cabal-Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ghc: [ "8.10", "8.4" ]
ghc: [ "8.10", "8.6" ]
steps:

- name: "Git checkout"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/On-Release-Cabal-Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
# Since CI by default tests boundary GHCs, test middle versions of GHCs
ghc: [ "8.8", "8.6"]
ghc: [ "8.8" ]
steps:
- name: "Git checkout"
uses: actions/checkout@v2
Expand Down
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@
* [(link)](https://github.com/haskell-nix/hnix/pull/878/files) `Nix.Pretty`: `mkNixDoc`: got unflipped.

* [(link)](https://github.com/haskell-nix/hnix/pull/886/commits/381b0e5df9cc620a25533ff1c84045a4ea37a833) `Nix.Value`: Data constructor for `NValue' t f m a` changed (`NValue -> NValue'`).

* [(link)](https://github.com/haskell-nix/hnix/pull/884/files) `Nix.Parser`: `Parser`: Data type was equivalent to `Either`, so became a type synonim for `Either`.

* [(link)](https://github.com/haskell-nix/hnix/pull/884/files) `Nix.Thunk.Basic`: `instance MonadThunk (NThunkF m v) m v`: `queryM`: implementation no longer blocks the thunk resource it only reads from.


* Additional:
* [(link)](https://github.com/haskell-nix/hnix/commit/7e6cd97bf3288cb584241611fdb25bf85d7e0ba7) `cabal.project`: freed from the `cryptohash-sha512` override, Hackage trustees made a revision.
Expand Down
776 changes: 392 additions & 384 deletions hnix.cabal

Large diffs are not rendered by default.

84 changes: 45 additions & 39 deletions main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,48 +85,54 @@ main = do
)
(readFrom opts)

processFile opts path = do
eres <- parseNixFileLoc path
handleResult opts (pure path) eres
processFile opts path =
do
eres <- parseNixFileLoc path
handleResult opts (pure path) eres

handleResult opts mpath = \case
Failure err ->
bool
errorWithoutStackTrace
(liftIO . hPutStrLn stderr)
(ignoreErrors opts)
$ "Parse failed: " <> show err
handleResult opts mpath =
either
(\ err ->
bool
errorWithoutStackTrace
(liftIO . hPutStrLn stderr)
(ignoreErrors opts)
$ "Parse failed: " <> show err
)

Success expr -> do
when (check opts) $ do
expr' <- liftIO (reduceExpr mpath expr)
either
(\ err -> errorWithoutStackTrace $ "Type error: " <> PS.ppShow err)
(\ ty -> liftIO $ putStrLn $ "Type of expression: " <> PS.ppShow
(fromJust $ Map.lookup "it" $ Env.types ty)
)
(HM.inferTop Env.empty [("it", stripAnnotation expr')])
(\ expr ->
do
when (check opts) $
do
expr' <- liftIO (reduceExpr mpath expr)
either
(\ err -> errorWithoutStackTrace $ "Type error: " <> PS.ppShow err)
(\ ty -> liftIO $ putStrLn $ "Type of expression: " <> PS.ppShow
(fromJust $ Map.lookup "it" $ Env.types ty)
)
(HM.inferTop Env.empty [("it", stripAnnotation expr')])

-- liftIO $ putStrLn $ runST $
-- runLintM opts . renderSymbolic =<< lint opts expr
-- liftIO $ putStrLn $ runST $
-- runLintM opts . renderSymbolic =<< lint opts expr

catch (process opts mpath expr) $ \case
NixException frames ->
errorWithoutStackTrace
. show
=<< renderFrames @(StdValue (StandardT (StdIdT IO)))
@(StdThunk (StandardT (StdIdT IO)))
frames
catch (process opts mpath expr) $
\case
NixException frames ->
errorWithoutStackTrace . show
=<< renderFrames @(StdValue (StandardT (StdIdT IO)))
@(StdThunk (StandardT (StdIdT IO)))
frames

when (repl opts) $
withNixContext mempty $
bool
Repl.main
(do
val <- Nix.nixEvalExprLoc mpath expr
Repl.main' $ pure val
)
(evaluate opts)
when (repl opts) $
withNixContext mempty $
bool
Repl.main
(do
val <- Nix.nixEvalExprLoc mpath expr
Repl.main' $ pure val
)
(evaluate opts)
)

process opts mpath expr
| evaluate opts =
Expand All @@ -137,8 +143,8 @@ main = do
&& null (argstr opts)
) -> evaluateExpression mpath Nix.nixEvalExprLoc printer expr
| otherwise -> processResult printer =<< Nix.nixEvalExprLoc mpath expr
| xml opts = error "Rendering expression trees to XML is not yet implemented"
| json opts = error "Rendering expression trees to JSON is not implemented"
| xml opts = fail "Rendering expression trees to XML is not yet implemented"
| json opts = fail "Rendering expression trees to JSON is not implemented"
| verbose opts >= DebugInfo = liftIO $ putStr $ PS.ppShow $ stripAnnotation expr
| cache opts
, Just path <- mpath = liftIO $ writeCache (addExtension (dropExtension path) "nixc") expr
Expand Down
Loading

0 comments on commit 4796681

Please sign in to comment.