Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unflip {mkNixDoc, nvSet{,'}}; refactors #878

Merged
merged 45 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6d614e8
Pretty: mkNixDoc: unflip
Anton-Latukha Mar 8, 2021
886d83b
Expr.Types.Annotated: fx inline directive
Anton-Latukha Mar 8, 2021
5583b0a
rm unused RankNTypes; Utils: embed RankNtypes `transport`
Anton-Latukha Mar 8, 2021
82754ad
Value: unflip nvSet{,'}
Anton-Latukha Mar 8, 2021
78651d4
Exec: refactor
Anton-Latukha Mar 8, 2021
d869d20
Exec: refactor
Anton-Latukha Mar 8, 2021
2a47a8e
(mappend -> <>)
Anton-Latukha Mar 8, 2021
b7acde7
Exec: m refactor
Anton-Latukha Mar 8, 2021
a0eba14
Effects: TOC the file structure
Anton-Latukha Mar 8, 2021
5cf0c7b
Effects: put derived instances into structure
Anton-Latukha Mar 8, 2021
90b828a
Eval: m refactor
Anton-Latukha Mar 8, 2021
6cf382e
Eval: refactor (includes (=<<) -> (<$>))
Anton-Latukha Mar 8, 2021
f529db9
Eval: refactor
Anton-Latukha Mar 8, 2021
a0edfaa
Lint: refactor
Anton-Latukha Mar 8, 2021
1d77b58
Lint: add ApplicativeDo extention - very fit here
Anton-Latukha Mar 8, 2021
152138e
Scope: refactor
Anton-Latukha Mar 8, 2021
2c3caf4
Scope: m refactor
Anton-Latukha Mar 8, 2021
0412ab8
(HashMap.empty -> mempty)
Anton-Latukha Mar 8, 2021
d936e95
{Set,Map}.empty-> mempty
Anton-Latukha Mar 8, 2021
0155454
Expr.Types: Alternative.empty -> mempty, it is used for []
Anton-Latukha Mar 8, 2021
d5d853d
Effects: m refactor
Anton-Latukha Mar 8, 2021
2b658fb
Parser: parseFromText: (=<< -> <$>)
Anton-Latukha Mar 8, 2021
9c4d123
Parser: refactor
Anton-Latukha Mar 8, 2021
bb1ebba
Parser: refactor
Anton-Latukha Mar 8, 2021
47b1f03
Parser: make imports explicit
Anton-Latukha Mar 9, 2021
9a7f07c
Parser: m refactor
Anton-Latukha Mar 9, 2021
2a4b7eb
Parser: add ApplicativeDo
Anton-Latukha Mar 9, 2021
200ca83
Value.Equal: refactor
Anton-Latukha Mar 9, 2021
84d9625
Value.Equal: refactor
Anton-Latukha Mar 9, 2021
884e16a
Type.Infer: refactor
Anton-Latukha Mar 9, 2021
9af8917
Builtins: refactor
Anton-Latukha Mar 9, 2021
a86140e
Reduce: reduce: refactor
Anton-Latukha Mar 9, 2021
ea6e8c5
Reduce: reduce: reduce (=<< -> <$>)
Anton-Latukha Mar 9, 2021
fab166d
Reduce: reduce: reduce <$>
Anton-Latukha Mar 9, 2021
78771ce
Eval: addStackFrames: nodge GHC to optimize it
Anton-Latukha Mar 9, 2021
6e23add
Builtins: Eval: evalBinds: (maybe -> =<<)
Anton-Latukha Mar 9, 2021
4e3aa9b
Pretty: refactor
Anton-Latukha Mar 9, 2021
a869b4e
Pretty: refactor
Anton-Latukha Mar 10, 2021
2b326e9
Pretty: refactor
Anton-Latukha Mar 10, 2021
f3e6887
Pretty: refactor
Anton-Latukha Mar 10, 2021
1a3c8e2
Pretty: refactor
Anton-Latukha Mar 10, 2021
24683c3
Pretty: refactor
Anton-Latukha Mar 10, 2021
5e88b8a
Exec: unflip nvSetP
Anton-Latukha Mar 11, 2021
b015ae2
ChangeLog: note on `nvSet{,',P}`
Anton-Latukha Mar 11, 2021
a802a10
ChangeLog: note about `mkNixDoc`
Anton-Latukha Mar 11, 2021
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
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@
MonadPaths (Fix1 t) :: Nix.Standard -> Nix.Effects
MonadPutStr (Fix1 t) :: Nix.Standard -> Nix.Effects
```
* [(link)](https://github.com/haskell-nix/hnix/pull/878/files) `nvSet{,',P}`: got unflipped, now accept source position argument before the value.

* [(link)](https://github.com/haskell-nix/hnix/pull/878/files) `mkNixDoc`: got unflipped.

* 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
2 changes: 1 addition & 1 deletion src/Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ evaluateExpression mpath evaluator handler expr = do

eval' = normalForm <=< nixEvalExpr mpath

argmap args = nvSet (M.fromList args) mempty
argmap args = nvSet mempty (M.fromList args)

processResult
:: forall e t f m a
Expand Down
46 changes: 25 additions & 21 deletions src/Nix/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,14 @@ withNixContext mpath action =
)
mpath

builtins :: (MonadNix e t f m, Scoped (NValue t f m) m)
=> m (Scopes m (NValue t f m))
builtins
:: ( MonadNix e t f m
, Scoped (NValue t f m) m
)
=> m (Scopes m (NValue t f m))
builtins =
do
ref <- defer $ (`nvSet` M.empty) <$> buildMap
ref <- defer $ nvSet mempty <$> buildMap
lst <- ([("builtins", ref)] <>) <$> topLevelBuiltins
pushScope (M.fromList lst) currentScopes
where
Expand Down Expand Up @@ -394,7 +397,7 @@ nixPath :: MonadNix e t f m => m (NValue t f m)
nixPath = fmap nvList $ flip foldNixPath mempty $
\p mn ty rest ->
pure $
flip nvSet
nvSet
mempty
(M.fromList
[case ty of
Expand Down Expand Up @@ -883,9 +886,10 @@ catAttrs attrName xs =
n <- fromStringNoContext =<< fromValue attrName
l <- fromValue @[NValue t f m] xs

fmap (nvList . catMaybes) $
forM l $
fmap (M.lookup n) . fromValue <=< demand
nvList . catMaybes <$>
traverse
(fmap (M.lookup n) . fromValue <=< demand)
l

baseNameOf :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
baseNameOf x = do
Expand Down Expand Up @@ -1010,7 +1014,7 @@ genList f nixN =
n <- fromValue @Integer nixN
bool
(throwError $ ErrorCall $ "builtins.genList: Expected a non-negative number, got " <> show n)
(toValue =<< forM [0 .. n - 1] (defer . callFunc f <=< toValue))
(toValue =<< traverse (defer . callFunc f <=< toValue) [0 .. n - 1])
(n >= 0)

-- We wrap values solely to provide an Ord instance for genericClosure
Expand Down Expand Up @@ -1195,7 +1199,7 @@ intersectAttrs set1 set2 =
(s1, p1) <- fromValue @(AttrSet (NValue t f m), AttrSet SourcePos) set1
(s2, p2) <- fromValue @(AttrSet (NValue t f m), AttrSet SourcePos) set2

pure $ nvSet (s2 `M.intersection` s1) (p2 `M.intersection` p1)
pure $ nvSet (p2 `M.intersection` p1) (s2 `M.intersection` s1)

functionArgs
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
Expand Down Expand Up @@ -1311,7 +1315,7 @@ throw_ mnv =

import_
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
import_ = scopedImport (nvSet M.empty M.empty)
import_ = scopedImport (nvSet mempty mempty)

scopedImport
:: forall e t f m
Expand Down Expand Up @@ -1433,17 +1437,17 @@ listToAttrs lst =
do
l <- fromValue @[NValue t f m] lst
fmap
((`nvSet` M.empty) . M.fromList . reverse)
(forM l $
(nvSet mempty . M.fromList . reverse)
(traverse
(\ nvattrset ->
do
a <- fromValue @(AttrSet (NValue t f m)) nvattrset
n <- fromValue =<< demand =<< attrsetGet "name" a
name <- fromStringNoContext n
a <- fromValue @(AttrSet (NValue t f m)) =<< demand nvattrset
name <- fromStringNoContext =<< fromValue =<< demand =<< attrsetGet "name" a
val <- attrsetGet "value" a

pure (name, val)
) <=< demand
)
l
)

-- prim_hashString from nix/src/libexpr/primops.cc
Expand Down Expand Up @@ -1596,7 +1600,7 @@ fromJSON nvjson =

where
jsonToNValue = \case
A.Object m -> (`nvSet` M.empty) <$> traverse jsonToNValue m
A.Object m -> nvSet mempty <$> traverse jsonToNValue m
A.Array l -> nvList <$> traverse jsonToNValue (V.toList l)
A.String s -> pure $ nvStr $ makeNixStringWithoutContext s
A.Number n ->
Expand Down Expand Up @@ -1643,12 +1647,12 @@ tryEval
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
tryEval e = catch (onSuccess <$> demand e) (pure . onError)
where
onSuccess v = flip nvSet M.empty $ M.fromList
onSuccess v = nvSet mempty $ M.fromList
[ ("success", nvConstant (NBool True))
, ("value", v)]

onError :: SomeException -> NValue t f m
onError _ = flip nvSet M.empty $ M.fromList
onError _ = nvSet mempty $ M.fromList
[ ("success", nvConstant (NBool False))
, ("value" , nvConstant (NBool False))
]
Expand All @@ -1664,7 +1668,7 @@ trace_ msg action =
traceEffect @t @f @m . Text.unpack . stringIgnoreContext =<< fromValue msg
pure action

-- 2018-09-08: NOTE: Remember of error context is so far not implemented
-- Please, can function remember error context
addErrorContext
:: forall e t f m
. MonadNix e t f m
Expand Down Expand Up @@ -1755,7 +1759,7 @@ getContext =
(NVStr ns) -> do
let context = getNixLikeContext $ toNixLikeContext $ NixString.getContext ns
valued :: M.HashMap Text (NValue t f m) <- sequenceA $ M.map toValue context
pure $ nvSet valued M.empty
pure $ nvSet mempty valued
x -> throwError $ ErrorCall $ "Invalid type for builtins.getContext: " <> show x) <=< demand

appendContext
Expand Down
26 changes: 14 additions & 12 deletions src/Nix/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ instance ( Convertible e t f m
l' <- toValue (unPos l)
c' <- toValue (unPos c)
let pos = M.fromList [("file" :: Text, f'), ("line", l'), ("column", c')]
pure $ nvSet' pos mempty
pure $ nvSet' mempty pos

-- | With 'ToValue', we can always act recursively
instance Convertible e t f m
Expand All @@ -404,33 +404,35 @@ instance (Convertible e t f m, ToValue a m (NValue t f m))

instance Convertible e t f m
=> ToValue (AttrSet (NValue t f m)) m (NValue' t f m (NValue t f m)) where
toValue s = pure $ nvSet' s mempty
toValue s = pure $ nvSet' mempty s

instance (Convertible e t f m, ToValue a m (NValue t f m))
=> ToValue (AttrSet a) m (Deeper (NValue' t f m (NValue t f m))) where
toValue s = (Deeper .) . nvSet' <$> traverse toValue s <*> pure mempty
toValue s = (\ v s -> Deeper $ nvSet' s v) <$> (traverse (toValue) s) <*> pure mempty

instance Convertible e t f m
=> ToValue (AttrSet (NValue t f m), AttrSet SourcePos) m
(NValue' t f m (NValue t f m)) where
toValue (s, p) = pure $ nvSet' s p
toValue (s, p) = pure $ nvSet' p s

instance (Convertible e t f m, ToValue a m (NValue t f m))
=> ToValue (AttrSet a, AttrSet SourcePos) m
(Deeper (NValue' t f m (NValue t f m))) where
toValue (s, p) = (Deeper .) . nvSet' <$> traverse toValue s <*> pure p
toValue (s, p) = (\ v s -> Deeper $ nvSet' s v) <$> (traverse (toValue) s) <*> pure p

instance Convertible e t f m
=> ToValue NixLikeContextValue m (NValue' t f m (NValue t f m)) where
toValue nlcv = do
path <-
if nlcvPath nlcv
then pure <$> toValue True
else pure Nothing
bool
(pure Nothing)
(pure <$> toValue True)
(nlcvPath nlcv)
allOutputs <-
if nlcvAllOutputs nlcv
then pure <$> toValue True
else pure Nothing
bool
(pure Nothing)
(pure <$> toValue True)
(nlcvAllOutputs nlcv)
outputs <- do
let
outputs = makeNixStringWithoutContext <$> nlcvOutputs nlcv
Expand All @@ -440,7 +442,7 @@ instance Convertible e t f m
(pure Nothing)
(fmap pure . toValue)
ts
pure $ flip nvSet' M.empty $ M.fromList $ catMaybes
pure $ nvSet' mempty $ M.fromList $ catMaybes
[ ("path",) <$> path
, ("allOutputs",) <$> allOutputs
, ("outputs",) <$> outputs
Expand Down
Loading