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 1 commit
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
Prev Previous commit
Next Next commit
Value: unflip nvSet{,'}
  • Loading branch information
Anton-Latukha committed Mar 8, 2021
commit 82754ad34dde3f54fd20693453ab87944cc8ae65
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
16 changes: 8 additions & 8 deletions src/Nix/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ 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 M.empty) <$> buildMap
lst <- ([("builtins", ref)] <>) <$> topLevelBuiltins
pushScope (M.fromList lst) currentScopes
where
Expand Down Expand Up @@ -394,7 +394,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 @@ -1195,7 +1195,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 @@ -1433,7 +1433,7 @@ listToAttrs lst =
do
l <- fromValue @[NValue t f m] lst
fmap
((`nvSet` M.empty) . M.fromList . reverse)
((nvSet M.empty) . M.fromList . reverse)
(forM l $
(\ nvattrset ->
do
Expand Down Expand Up @@ -1596,7 +1596,7 @@ fromJSON nvjson =

where
jsonToNValue = \case
A.Object m -> (`nvSet` M.empty) <$> traverse jsonToNValue m
A.Object m -> (nvSet M.empty) <$> 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 +1643,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 M.empty $ M.fromList
[ ("success", nvConstant (NBool True))
, ("value", v)]

onError :: SomeException -> NValue t f m
onError _ = flip nvSet M.empty $ M.fromList
onError _ = nvSet M.empty $ M.fromList
[ ("success", nvConstant (NBool False))
, ("value" , nvConstant (NBool False))
]
Expand Down Expand Up @@ -1755,7 +1755,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 M.empty 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' M.empty $ M.fromList $ catMaybes
[ ("path",) <$> path
, ("allOutputs",) <$> allOutputs
, ("outputs",) <$> outputs
Expand Down
6 changes: 3 additions & 3 deletions src/Nix/Effects/Derivation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ defaultDerivationStrict = fromValue @(AttrSet (NValue t f m)) >=> \s -> do

-- Memoize here, as it may be our last chance in case of readonly stores.
drvHash <- Store.encodeInBase Store.Base16 <$> hashDerivationModulo drv'
modify (\(a, b) -> (a, MS.insert drvPath drvHash b))
modify (second (MS.insert drvPath drvHash))

let outputsWithContext = Map.mapWithKey (\out path -> makeNixStringWithSingletonContext path (StringContext drvPath (DerivationOutput out))) (outputs drv')
drvPathWithContext = makeNixStringWithSingletonContext drvPath (StringContext drvPath AllOutputs)
attrSet = M.map nvStr $ M.fromList $ ("drvPath", drvPathWithContext): Map.toList outputsWithContext
-- TODO: Add location information for all the entries.
-- here --v
pure $ nvSet attrSet M.empty
pure $ nvSet M.empty attrSet

where

Expand Down Expand Up @@ -328,7 +328,7 @@ buildDerivationWithContext drvAttrs = do

env <- if useJson
then do
jsonString :: NixString <- lift $ nvalueToJSONNixString $ flip nvSet M.empty $
jsonString :: NixString <- lift $ nvalueToJSONNixString $ nvSet M.empty $
deleteKeys [ "args", "__ignoreNulls", "__structuredAttrs" ] attrs
rawString :: Text <- extractNixString jsonString
pure $ Map.singleton "__json" rawString
Expand Down
2 changes: 1 addition & 1 deletion src/Nix/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ nvSetP
-> AttrSet (NValue t f m)
-> AttrSet SourcePos
-> NValue t f m
nvSetP p s x = addProvenance p (nvSet s x)
nvSetP p s x = addProvenance p (nvSet x s)

nvClosureP
:: MonadCited t f m
Expand Down
12 changes: 6 additions & 6 deletions src/Nix/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ nvList' = NValue . pure . NVListF

-- | Haskell key-value to the Nix key-value,
nvSet' :: Applicative f
=> HashMap Text r
-> HashMap Text SourcePos
=> HashMap Text SourcePos
-> HashMap Text r
-> NValue' t f m r
nvSet' s x = NValue $ pure $ NVSetF s x
nvSet' x s = NValue $ pure $ NVSetF s x


-- | Haskell closure to the Nix closure,
Expand Down Expand Up @@ -549,10 +549,10 @@ nvList = Free . nvList'


nvSet :: Applicative f
=> HashMap Text (NValue t f m)
-> HashMap Text SourcePos
=> HashMap Text SourcePos
-> HashMap Text (NValue t f m)
-> NValue t f m
nvSet s x = Free $ nvSet' s x
nvSet x s = Free $ nvSet' x s


nvClosure :: (Applicative f, Functor m)
Expand Down