Skip to content

Commit

Permalink
treewide: use pattern AnnE, add doc to it
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-Latukha committed May 18, 2021
1 parent ef2700b commit 46a82e3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
14 changes: 6 additions & 8 deletions src/Nix/Cited/Basic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Prelude hiding ( force )
import Control.Comonad ( Comonad )
import Control.Comonad.Env ( ComonadEnv )
import Control.Monad.Catch hiding ( catchJust )
import Data.Fix
import Nix.Cited
import Nix.Eval as Eval
import Nix.Exec
Expand Down Expand Up @@ -64,13 +63,12 @@ instance ( Has e Options

-- Gather the current evaluation context at the time of thunk
-- creation, and record it along with the thunk.
let go (fromException ->
Just (EvaluatingExpr scope
(Fix (Compose (Ann s e))))) =
let e' = Compose (Ann s (Nothing <$ e))
in [Provenance scope e']
go _ = mempty
ps = concatMap (go . frame) frames
let
go (fromException -> Just (EvaluatingExpr scope (AnnE s e))) =
let e' = Compose (Ann s (Nothing <$ e)) in
[Provenance scope e']
go _ = mempty
ps = concatMap (go . frame) frames

Cited . NCited ps <$> thunk mv
)
Expand Down
3 changes: 1 addition & 2 deletions src/Nix/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module Nix.Eval where
import Control.Monad ( foldM )
import Control.Monad.Fix ( MonadFix )
import Data.Semialign.Indexed ( ialignWith )
import Data.Fix ( Fix(Fix) )
import qualified Data.HashMap.Lazy as M
import Data.List ( partition )
import Data.These ( These(..) )
Expand Down Expand Up @@ -496,7 +495,7 @@ buildArgument params arg =

addSourcePositions
:: (MonadReader e m, Has e SrcSpan) => Transform NExprLocF (m a)
addSourcePositions f v@(Fix (Compose (Ann ann _))) =
addSourcePositions f v@(AnnE ann _) =
local (set hasLens ann) $ f v

addStackFrames
Expand Down
1 change: 1 addition & 0 deletions src/Nix/Expr/Types/Annotated.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ data Ann ann a = Ann

type AnnF ann f = Compose (Ann ann) f

-- | Pattern: @Fix (Compose (Ann _ _))@.
pattern AnnE
:: forall ann (g :: * -> *)
. ann
Expand Down
14 changes: 7 additions & 7 deletions src/Nix/Reduce.hs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ pruneTree opts =
(reduceSets opts) -- Reduce set members that aren't used; breaks if hasAttr is used
binds

NLet binds (Just body@(Fix (Compose (Ann _ x)))) ->
NLet binds (Just body@(AnnE _ x)) ->
pure $
list
x
Expand All @@ -384,8 +384,8 @@ pruneTree opts =
pure $ NSelect aset (NE.map pruneKeyName attr) (join alt)

-- These are the only short-circuiting binary operators
NBinary NAnd (Just (Fix (Compose (Ann _ larg)))) _ -> pure larg
NBinary NOr (Just (Fix (Compose (Ann _ larg)))) _ -> pure larg
NBinary NAnd (Just (AnnE _ larg)) _ -> pure larg
NBinary NOr (Just (AnnE _ larg)) _ -> pure larg

-- If the function was never called, it means its argument was in a
-- thunk that was forced elsewhere.
Expand All @@ -399,18 +399,18 @@ pruneTree opts =
NBinary op (Just larg) Nothing -> pure $ NBinary op larg nNull

-- If the scope of a with was never referenced, it's not needed
NWith Nothing (Just (Fix (Compose (Ann _ body)))) -> pure body
NWith Nothing (Just (AnnE _ body)) -> pure body

NAssert Nothing _ ->
fail "How can an assert be used, but its condition not?"

NAssert _ (Just (Fix (Compose (Ann _ body)))) -> pure body
NAssert _ (Just (AnnE _ body)) -> pure body
NAssert (Just cond) _ -> pure $ NAssert cond nNull

NIf Nothing _ _ -> fail "How can an if be used, but its condition not?"

NIf _ Nothing (Just (Fix (Compose (Ann _ f)))) -> pure f
NIf _ (Just (Fix (Compose (Ann _ t)))) Nothing -> pure t
NIf _ Nothing (Just (AnnE _ f)) -> pure f
NIf _ (Just (AnnE _ t)) Nothing -> pure t

x -> sequence x

Expand Down
10 changes: 5 additions & 5 deletions src/Nix/Render/Frame.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ framePos
-> Maybe SourcePos
framePos (NixFrame _ f)
| Just (e :: EvalFrame m v) <- fromException f = case e of
EvaluatingExpr _ (Fix (Compose (Ann (SrcSpan beg _) _))) -> pure beg
EvaluatingExpr _ (AnnE (SrcSpan beg _) _) -> pure beg
_ -> Nothing
| otherwise = Nothing

Expand Down Expand Up @@ -108,7 +108,7 @@ renderEvalFrame level f =
do
opts :: Options <- asks (view hasLens)
case f of
EvaluatingExpr scope e@(Fix (Compose (Ann ann _))) ->
EvaluatingExpr scope e@(AnnE ann _) ->
do
let
scopeInfo =
Expand All @@ -121,7 +121,7 @@ renderEvalFrame level f =
$ renderLocation ann =<<
renderExpr level "While evaluating" "Expression" e

ForcingExpr _scope e@(Fix (Compose (Ann ann _))) | thunks opts ->
ForcingExpr _scope e@(AnnE ann _) | thunks opts ->
fmap
(: mempty)
$ renderLocation ann =<<
Expand All @@ -135,7 +135,7 @@ renderEvalFrame level f =

SynHole synfo ->
sequence $
let e@(Fix (Compose (Ann ann _))) = _synHoleInfo_expr synfo in
let e@(AnnE ann _) = _synHoleInfo_expr synfo in

[ renderLocation ann =<<
renderExpr level "While evaluating" "Syntactic Hole" e
Expand All @@ -152,7 +152,7 @@ renderExpr
-> Text
-> NExprLoc
-> m (Doc ann)
renderExpr _level longLabel shortLabel e@(Fix (Compose (Ann _ x))) = do
renderExpr _level longLabel shortLabel e@(AnnE _ x) = do
opts :: Options <- asks (view hasLens)
let rendered
| verbose opts >= DebugInfo =
Expand Down

0 comments on commit 46a82e3

Please sign in to comment.