From 402aeb6c25bebb2ab656e7e1d3d68d6d264f599a Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Thu, 21 Jan 2021 11:30:50 +0200 Subject: [PATCH 01/19] make orphan instance warnings explicit --- src/Nix/Exec.hs | 1 - src/Nix/Expr/Types.hs | 2 +- src/Nix/Fresh.hs | 2 +- src/Nix/Fresh/Basic.hs | 2 +- src/Nix/Pretty.hs | 2 +- src/Nix/Reduce.hs | 2 +- src/Nix/Standard.hs | 2 +- src/Nix/Thunk/Basic.hs | 2 +- src/Nix/Value/Equal.hs | 1 - src/Nix/Var.hs | 2 +- tests/EvalTests.hs | 2 +- tests/ParserTests.hs | 2 +- tests/PrettyParseTests.hs | 1 + 13 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Nix/Exec.hs b/src/Nix/Exec.hs index 5b18e8fd8..cbe71ba3e 100644 --- a/src/Nix/Exec.hs +++ b/src/Nix/Exec.hs @@ -15,7 +15,6 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} -{-# OPTIONS_GHC -Wno-orphans #-} {-# OPTIONS_GHC -fno-warn-name-shadowing #-} module Nix.Exec where diff --git a/src/Nix/Expr/Types.hs b/src/Nix/Expr/Types.hs index cb295bcab..051dda2d7 100644 --- a/src/Nix/Expr/Types.hs +++ b/src/Nix/Expr/Types.hs @@ -17,7 +17,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE InstanceSigs #-} -{-# OPTIONS_GHC -Wno-orphans #-} + {-# OPTIONS_GHC -Wno-missing-signatures #-} -- | The Nix expression type and supporting types. diff --git a/src/Nix/Fresh.hs b/src/Nix/Fresh.hs index a52e1152e..ed5793555 100644 --- a/src/Nix/Fresh.hs +++ b/src/Nix/Fresh.hs @@ -8,7 +8,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} -{-# OPTIONS_GHC -Wno-orphans #-} + module Nix.Fresh where diff --git a/src/Nix/Fresh/Basic.hs b/src/Nix/Fresh/Basic.hs index a6c48e999..be5c20972 100644 --- a/src/Nix/Fresh/Basic.hs +++ b/src/Nix/Fresh/Basic.hs @@ -5,7 +5,7 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeSynonymInstances #-} -{-# OPTIONS_GHC -Wno-orphans #-} + module Nix.Fresh.Basic where diff --git a/src/Nix/Pretty.hs b/src/Nix/Pretty.hs index 42fc9e5fa..3690271d1 100644 --- a/src/Nix/Pretty.hs +++ b/src/Nix/Pretty.hs @@ -10,7 +10,7 @@ {-# LANGUAGE ViewPatterns #-} {-# OPTIONS_GHC -fno-warn-name-shadowing #-} -{-# OPTIONS_GHC -Wno-orphans #-} + module Nix.Pretty where diff --git a/src/Nix/Reduce.hs b/src/Nix/Reduce.hs index 024ba46f7..ed289aece 100644 --- a/src/Nix/Reduce.hs +++ b/src/Nix/Reduce.hs @@ -17,7 +17,7 @@ {-# LANGUAGE ViewPatterns #-} {-# OPTIONS_GHC -fno-warn-name-shadowing #-} -{-# OPTIONS_GHC -Wno-orphans #-} + -- | This module provides a "reducing" expression evaluator, which reduces -- away pure, non self-referential aspects of an expression tree, yielding a diff --git a/src/Nix/Standard.hs b/src/Nix/Standard.hs index ac601d6c6..c55a452f0 100644 --- a/src/Nix/Standard.hs +++ b/src/Nix/Standard.hs @@ -14,7 +14,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} -{-# OPTIONS_GHC -Wno-orphans #-} + module Nix.Standard where diff --git a/src/Nix/Thunk/Basic.hs b/src/Nix/Thunk/Basic.hs index 66d526fba..5e25b17b1 100644 --- a/src/Nix/Thunk/Basic.hs +++ b/src/Nix/Thunk/Basic.hs @@ -7,7 +7,7 @@ {-# LANGUAGE TupleSections #-} {-# LANGUAGE UndecidableInstances #-} -{-# OPTIONS_GHC -Wno-orphans #-} + module Nix.Thunk.Basic (NThunkF(..), Deferred(..), MonadBasicThunk) where diff --git a/src/Nix/Value/Equal.hs b/src/Nix/Value/Equal.hs index 509c0317a..57ac39bc6 100644 --- a/src/Nix/Value/Equal.hs +++ b/src/Nix/Value/Equal.hs @@ -20,7 +20,6 @@ {-# LANGUAGE TypeOperators #-} {-# LANGUAGE ViewPatterns #-} -{-# OPTIONS_GHC -Wno-orphans #-} {-# OPTIONS_GHC -Wno-missing-pattern-synonym-signatures #-} module Nix.Value.Equal where diff --git a/src/Nix/Var.hs b/src/Nix/Var.hs index cae8cac92..0b56d98ce 100644 --- a/src/Nix/Var.hs +++ b/src/Nix/Var.hs @@ -3,7 +3,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# OPTIONS_GHC -Wno-orphans #-} + module Nix.Var where diff --git a/tests/EvalTests.hs b/tests/EvalTests.hs index 8cb7c1b48..2e99ca36e 100644 --- a/tests/EvalTests.hs +++ b/tests/EvalTests.hs @@ -4,7 +4,7 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -Wno-missing-signatures #-} + module EvalTests (tests, genEvalCompareTests) where diff --git a/tests/ParserTests.hs b/tests/ParserTests.hs index a3e55687b..0439b4075 100644 --- a/tests/ParserTests.hs +++ b/tests/ParserTests.hs @@ -4,7 +4,7 @@ {-# LANGUAGE RankNTypes #-} {-# OPTIONS_GHC -fno-warn-name-shadowing #-} -{-# OPTIONS_GHC -Wno-missing-signatures -Wno-orphans #-} + module ParserTests (tests) where diff --git a/tests/PrettyParseTests.hs b/tests/PrettyParseTests.hs index 4e175ab9d..026be2ae6 100644 --- a/tests/PrettyParseTests.hs +++ b/tests/PrettyParseTests.hs @@ -7,6 +7,7 @@ {-# LANGUAGE OverloadedStrings #-} + module PrettyParseTests where import Data.Algorithm.Diff From b68cb66a56216f2f8a5c7ed5d9d0332474cc4348 Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Thu, 7 Jan 2021 17:52:39 +0200 Subject: [PATCH 02/19] move instance Binary NAtom to the parent --- src/Nix/Atoms.hs | 5 ++++- src/Nix/Expr/Types.hs | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Nix/Atoms.hs b/src/Nix/Atoms.hs index 24f9091e5..0a6d5a3fc 100644 --- a/src/Nix/Atoms.hs +++ b/src/Nix/Atoms.hs @@ -11,12 +11,13 @@ import Codec.Serialise #endif import Control.DeepSeq import Data.Data -import Data.Fixed (mod') +import Data.Fixed ( mod' ) import Data.Hashable import Data.Text ( Text , pack ) import GHC.Generics +import Data.Binary ( Binary ) -- | Atoms are values that evaluate to themselves. This means that -- they appear in both the parsed AST (in the form of literals) and @@ -40,6 +41,8 @@ data NAtom instance Serialise NAtom #endif +instance Binary NAtom + -- | Translate an atom into its nix representation. atomText :: NAtom -> Text atomText (NURI t) = t diff --git a/src/Nix/Expr/Types.hs b/src/Nix/Expr/Types.hs index 051dda2d7..05ef1e645 100644 --- a/src/Nix/Expr/Types.hs +++ b/src/Nix/Expr/Types.hs @@ -530,7 +530,6 @@ instance Binary Pos where instance Binary SourcePos instance Binary a => Binary (NKeyName a) instance Binary a => Binary (Params a) -instance Binary NAtom instance Binary NUnaryOp instance Binary NBinaryOp instance Binary NRecordType From 71f50b24cba914ff322e8669251bf2f243ee91d1 Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Thu, 7 Jan 2021 18:25:44 +0200 Subject: [PATCH 03/19] move instances {From,To}JSON NAtom to the parent --- src/Nix/Atoms.hs | 3 +++ src/Nix/Expr/Types.hs | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Nix/Atoms.hs b/src/Nix/Atoms.hs index 0a6d5a3fc..6174727c2 100644 --- a/src/Nix/Atoms.hs +++ b/src/Nix/Atoms.hs @@ -18,6 +18,7 @@ import Data.Text ( Text ) import GHC.Generics import Data.Binary ( Binary ) +import Data.Aeson.Types ( FromJSON, ToJSON ) -- | Atoms are values that evaluate to themselves. This means that -- they appear in both the parsed AST (in the form of literals) and @@ -42,6 +43,8 @@ instance Serialise NAtom #endif instance Binary NAtom +instance ToJSON NAtom +instance FromJSON NAtom -- | Translate an atom into its nix representation. atomText :: NAtom -> Text diff --git a/src/Nix/Expr/Types.hs b/src/Nix/Expr/Types.hs index 05ef1e645..03456c277 100644 --- a/src/Nix/Expr/Types.hs +++ b/src/Nix/Expr/Types.hs @@ -543,7 +543,6 @@ instance ToJSON Pos where instance ToJSON SourcePos instance ToJSON a => ToJSON (NKeyName a) instance ToJSON a => ToJSON (Params a) -instance ToJSON NAtom instance ToJSON NUnaryOp instance ToJSON NBinaryOp instance ToJSON NRecordType @@ -557,7 +556,6 @@ instance FromJSON Pos where instance FromJSON SourcePos instance FromJSON a => FromJSON (NKeyName a) instance FromJSON a => FromJSON (Params a) -instance FromJSON NAtom instance FromJSON NUnaryOp instance FromJSON NBinaryOp instance FromJSON NRecordType From 3a99b1645f302235e17b496d13c245d6cc48c900 Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Thu, 7 Jan 2021 18:39:21 +0200 Subject: [PATCH 04/19] move instances HasCitations1 NValue to the parent --- src/Nix/Cited.hs | 14 ++++++++++++++ src/Nix/Pretty.hs | 12 ------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Nix/Cited.hs b/src/Nix/Cited.hs index f993c5f53..90855df83 100644 --- a/src/Nix/Cited.hs +++ b/src/Nix/Cited.hs @@ -18,6 +18,8 @@ import Lens.Family2.TH import Nix.Expr.Types.Annotated import Nix.Scope +import Nix.Value ( NValue, NValue'(NValue) ) +import Control.Monad.Free ( Free(Pure, Free) ) data Provenance m v = Provenance { _lexicalScope :: Scopes m v @@ -60,3 +62,15 @@ instance HasCitations m v (NCited m v a) where class HasCitations1 m v f where citations1 :: f a -> [Provenance m v] addProvenance1 :: Provenance m v -> f a -> f a + +instance HasCitations1 m v f + => HasCitations m v (NValue' t f m a) where + citations (NValue f) = citations1 f + addProvenance x (NValue f) = NValue (addProvenance1 x f) + +instance (HasCitations1 m v f, HasCitations m v t) + => HasCitations m v (NValue t f m) where + citations (Pure t) = citations t + citations (Free v) = citations v + addProvenance x (Pure t) = Pure (addProvenance x t) + addProvenance x (Free v) = Free (addProvenance x v) diff --git a/src/Nix/Pretty.hs b/src/Nix/Pretty.hs index 3690271d1..2b1c28499 100644 --- a/src/Nix/Pretty.hs +++ b/src/Nix/Pretty.hs @@ -184,18 +184,6 @@ prettyAtom atom = simpleExpr $ pretty $ unpack $ atomText atom prettyNix :: NExpr -> Doc ann prettyNix = withoutParens . foldFix exprFNixDoc -instance HasCitations1 m v f - => HasCitations m v (NValue' t f m a) where - citations (NValue f) = citations1 f - addProvenance x (NValue f) = NValue (addProvenance1 x f) - -instance (HasCitations1 m v f, HasCitations m v t) - => HasCitations m v (NValue t f m) where - citations (Pure t) = citations t - citations (Free v) = citations v - addProvenance x (Pure t) = Pure (addProvenance x t) - addProvenance x (Free v) = Free (addProvenance x v) - prettyOriginExpr :: forall t f m ann . HasCitations1 m (NValue t f m) f From bca38685d462299b33225ab63b2d7f9a6e5af779 Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Thu, 7 Jan 2021 19:40:56 +0200 Subject: [PATCH 05/19] move instance Eq1 NValueF to the parent --- src/Nix/Value.hs | 11 ++++++++++- src/Nix/Value/Equal.hs | 9 --------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Nix/Value.hs b/src/Nix/Value.hs index e5b1c1e22..93f7452c7 100644 --- a/src/Nix/Value.hs +++ b/src/Nix/Value.hs @@ -28,7 +28,8 @@ import Control.Monad.Trans.Class ( MonadTrans, lift ) import qualified Data.Aeson as A import Data.Functor.Classes ( Show1 , liftShowsPrec - , showsUnaryWith ) + , showsUnaryWith + , Eq1(liftEq) ) import Data.HashMap.Lazy ( HashMap ) import Data.Text ( Text ) import Data.Typeable ( Typeable ) @@ -100,6 +101,14 @@ instance Show r => Show (NValueF p m r) where showsCon1 con a d = showParen (d > 10) $ showString (con <> " ") . showsPrec 11 a +instance Eq1 (NValueF p m) where + liftEq _ (NVConstantF x) (NVConstantF y) = x == y + liftEq _ (NVStrF x) (NVStrF y) = x == y + liftEq eq (NVListF x) (NVListF y) = liftEq eq x y + liftEq eq (NVSetF x _ ) (NVSetF y _ ) = liftEq eq x y + liftEq _ (NVPathF x ) (NVPathF y ) = x == y + liftEq _ _ _ = False + lmapNValueF :: Functor m => (b -> a) -> NValueF a m r -> NValueF b m r lmapNValueF f = \case NVConstantF a -> NVConstantF a diff --git a/src/Nix/Value/Equal.hs b/src/Nix/Value/Equal.hs index 57ac39bc6..12c2cc4ce 100644 --- a/src/Nix/Value/Equal.hs +++ b/src/Nix/Value/Equal.hs @@ -31,7 +31,6 @@ import Control.Monad.Trans.Class import Control.Monad.Trans.Except import Data.Align import Data.Eq.Deriving -import Data.Functor.Classes import Data.Functor.Identity import qualified Data.HashMap.Lazy as M import Data.These @@ -175,12 +174,4 @@ thunkEqM lt rt = force lt $ \lv -> force rt $ \rv -> (NVSet _ _ , NVSet _ _ ) -> unsafePtrEq _ -> valueEqM lv rv -instance Eq1 (NValueF p m) where - liftEq _ (NVConstantF x) (NVConstantF y) = x == y - liftEq _ (NVStrF x) (NVStrF y) = x == y - liftEq eq (NVListF x) (NVListF y) = liftEq eq x y - liftEq eq (NVSetF x _ ) (NVSetF y _ ) = liftEq eq x y - liftEq _ (NVPathF x ) (NVPathF y ) = x == y - liftEq _ _ _ = False - $(deriveEq1 ''NValue') From 6c15ed765f95020d8a348137913f1806c5162016 Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Thu, 7 Jan 2021 19:44:11 +0200 Subject: [PATCH 06/19] move TH instance Eq1 NValue' to the parent as derivable Eq1 instance was previously derived as an orphan through TemplateHaskell. And that TH instance when moved into Nix.Value was breaking the NValue' data constructor deriving. So it is moved as derivable instance. --- src/Nix/Value.hs | 2 +- src/Nix/Value/Equal.hs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Nix/Value.hs b/src/Nix/Value.hs index 93f7452c7..591526431 100644 --- a/src/Nix/Value.hs +++ b/src/Nix/Value.hs @@ -180,7 +180,7 @@ type MonadDataContext f (m :: * -> *) -- | At the time of constructor, the expected arguments to closures are values -- that may contain thunks. The type of such thunks are fixed at that time. newtype NValue' t f m a = NValue { _nValue :: f (NValueF (NValue t f m) m a) } - deriving (Generic, Typeable, Functor, Foldable) + deriving (Generic, Typeable, Functor, Foldable, Eq1) instance (Comonad f, Show a) => Show (NValue' t f m a) where show (NValue (extract -> v)) = show v diff --git a/src/Nix/Value/Equal.hs b/src/Nix/Value/Equal.hs index 12c2cc4ce..d791765f8 100644 --- a/src/Nix/Value/Equal.hs +++ b/src/Nix/Value/Equal.hs @@ -30,7 +30,6 @@ import Control.Monad.Free import Control.Monad.Trans.Class import Control.Monad.Trans.Except import Data.Align -import Data.Eq.Deriving import Data.Functor.Identity import qualified Data.HashMap.Lazy as M import Data.These @@ -173,5 +172,3 @@ thunkEqM lt rt = force lt $ \lv -> force rt $ \rv -> (NVList _ , NVList _ ) -> unsafePtrEq (NVSet _ _ , NVSet _ _ ) -> unsafePtrEq _ -> valueEqM lv rv - -$(deriveEq1 ''NValue') From 323c31205d992966c41f62012c36b3b3faf169e5 Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Thu, 7 Jan 2021 19:58:12 +0200 Subject: [PATCH 07/19] Nix/Exec: note to the instance MonadEval NValue --- src/Nix/Exec.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Nix/Exec.hs b/src/Nix/Exec.hs index cbe71ba3e..922cffbc3 100644 --- a/src/Nix/Exec.hs +++ b/src/Nix/Exec.hs @@ -152,6 +152,8 @@ currentPos = asks (view hasLens) wrapExprLoc :: SrcSpan -> NExprLocF r -> NExprLoc wrapExprLoc span x = Fix (Fix (NSym_ span "") <$ x) +-- 2021-01-07: NOTE: This instance belongs to be beside MonadEval type class. +-- Currently instance is stuck in orphanage between the requirements to be MonadEval, aka Eval stage, and emposed requirement to be MonadNix (Execution stage). MonadNix constraint tries to put the cart before horse and seems superflous, since Eval in Nix also needs and can throw exceptions. It is between `nverr` and `evalError`. instance MonadNix e t f m => MonadEval (NValue t f m) m where freeVariable var = nverr @e @t @f From b5ef4426c309f68628a4cde35272262432f719a3 Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Thu, 7 Jan 2021 20:16:08 +0200 Subject: [PATCH 08/19] Expr/Types: rm orphan instances Hashable1 {NonEmpty,NExprF,Binding} --- src/Nix/Expr/Types.hs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Nix/Expr/Types.hs b/src/Nix/Expr/Types.hs index 03456c277..5df335dbe 100644 --- a/src/Nix/Expr/Types.hs +++ b/src/Nix/Expr/Types.hs @@ -73,9 +73,6 @@ type VarName = Text hashAt :: VarName -> Lens' (AttrSet v) (Maybe v) hashAt = flip alterF --- unfortunate orphans -instance Hashable1 NonEmpty - -- | The main Nix expression type. As it is polimophic, has a functor, -- which allows to traverse expressions and map functions over them. -- The actual 'NExpr' type is a fixed point of this functor, defined @@ -163,8 +160,6 @@ data NExprF r deriving (Ord, Eq, Generic, Generic1, Typeable, Data, Functor, Foldable, Traversable, Show, NFData, Hashable) -instance Hashable1 NExprF - instance NFData1 NExprF #ifdef MIN_VERSION_serialise @@ -213,8 +208,6 @@ data Binding r deriving (Generic, Generic1, Typeable, Data, Ord, Eq, Functor, Foldable, Traversable, Show, NFData, Hashable) -instance Hashable1 Binding - instance NFData1 Binding #ifdef MIN_VERSION_serialise From 1131205668ad7fa5668ef439805f8f4a98655f0a Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Thu, 7 Jan 2021 20:17:45 +0200 Subject: [PATCH 09/19] move Fix1{,T} instances to the type class parent Since type class is up the structure - move instances there. --- src/Nix/Effects.hs | 22 ++++++++++++++++++++++ src/Nix/Standard.hs | 20 +------------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/Nix/Effects.hs b/src/Nix/Effects.hs index 24533a955..e7bffcc01 100644 --- a/src/Nix/Effects.hs +++ b/src/Nix/Effects.hs @@ -9,6 +9,9 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeApplications #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE UndecidableInstances #-} module Nix.Effects where @@ -26,6 +29,7 @@ import qualified Data.Text.Encoding as T import Network.HTTP.Client hiding ( path, Proxy ) import Network.HTTP.Client.TLS import Network.HTTP.Types +import Nix.Utils.Fix1 import Nix.Expr import Nix.Frames hiding ( Proxy ) import Nix.Parser @@ -286,3 +290,21 @@ addPath p = either throwError return =<< addToStore (T.pack $ takeFileName p) p toFile_ :: (Framed e m, MonadStore m) => FilePath -> String -> m StorePath toFile_ p contents = addTextToStore (T.pack p) (T.pack contents) HS.empty False + +-- All of the following type classes defer to the underlying 'm'. + +deriving instance MonadPutStr (t (Fix1 t)) => MonadPutStr (Fix1 t) +deriving instance MonadHttp (t (Fix1 t)) => MonadHttp (Fix1 t) +deriving instance MonadEnv (t (Fix1 t)) => MonadEnv (Fix1 t) +deriving instance MonadPaths (t (Fix1 t)) => MonadPaths (Fix1 t) +deriving instance MonadInstantiate (t (Fix1 t)) => MonadInstantiate (Fix1 t) +deriving instance MonadExec (t (Fix1 t)) => MonadExec (Fix1 t) +deriving instance MonadIntrospect (t (Fix1 t)) => MonadIntrospect (Fix1 t) + +deriving instance MonadPutStr (t (Fix1T t m) m) => MonadPutStr (Fix1T t m) +deriving instance MonadHttp (t (Fix1T t m) m) => MonadHttp (Fix1T t m) +deriving instance MonadEnv (t (Fix1T t m) m) => MonadEnv (Fix1T t m) +deriving instance MonadPaths (t (Fix1T t m) m) => MonadPaths (Fix1T t m) +deriving instance MonadInstantiate (t (Fix1T t m) m) => MonadInstantiate (Fix1T t m) +deriving instance MonadExec (t (Fix1T t m) m) => MonadExec (Fix1T t m) +deriving instance MonadIntrospect (t (Fix1T t m) m) => MonadIntrospect (Fix1T t m) diff --git a/src/Nix/Standard.hs b/src/Nix/Standard.hs index c55a452f0..f09ce7868 100644 --- a/src/Nix/Standard.hs +++ b/src/Nix/Standard.hs @@ -6,12 +6,11 @@ {-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE UndecidableInstances #-} @@ -53,23 +52,6 @@ import Nix.Value import Nix.Value.Monad import Nix.Var --- All of the following type classes defer to the underlying 'm'. - -deriving instance MonadPutStr (t (Fix1 t)) => MonadPutStr (Fix1 t) -deriving instance MonadHttp (t (Fix1 t)) => MonadHttp (Fix1 t) -deriving instance MonadEnv (t (Fix1 t)) => MonadEnv (Fix1 t) -deriving instance MonadPaths (t (Fix1 t)) => MonadPaths (Fix1 t) -deriving instance MonadInstantiate (t (Fix1 t)) => MonadInstantiate (Fix1 t) -deriving instance MonadExec (t (Fix1 t)) => MonadExec (Fix1 t) -deriving instance MonadIntrospect (t (Fix1 t)) => MonadIntrospect (Fix1 t) - -deriving instance MonadPutStr (t (Fix1T t m) m) => MonadPutStr (Fix1T t m) -deriving instance MonadHttp (t (Fix1T t m) m) => MonadHttp (Fix1T t m) -deriving instance MonadEnv (t (Fix1T t m) m) => MonadEnv (Fix1T t m) -deriving instance MonadPaths (t (Fix1T t m) m) => MonadPaths (Fix1T t m) -deriving instance MonadInstantiate (t (Fix1T t m) m) => MonadInstantiate (Fix1T t m) -deriving instance MonadExec (t (Fix1T t m) m) => MonadExec (Fix1T t m) -deriving instance MonadIntrospect (t (Fix1T t m) m) => MonadIntrospect (Fix1T t m) type MonadFix1T t m = (MonadTrans (Fix1T t), Monad (t (Fix1T t m) m)) From 902e6dd867bfc50bab9a58a0ce68a50f7ad94f39 Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Fri, 8 Jan 2021 00:19:35 +0200 Subject: [PATCH 10/19] move instances Monad{,Atomic}Ref Fix1T to the parent --- src/Nix/Standard.hs | 16 ++-------------- src/Nix/Utils/Fix1.hs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/Nix/Standard.hs b/src/Nix/Standard.hs index f09ce7868..705af05d9 100644 --- a/src/Nix/Standard.hs +++ b/src/Nix/Standard.hs @@ -1,15 +1,14 @@ +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE KindSignatures #-} {-# LANGUAGE CPP #-} -{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DeriveFoldable #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveTraversable #-} -{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} -{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE UndecidableInstances #-} @@ -53,17 +52,6 @@ import Nix.Value.Monad import Nix.Var -type MonadFix1T t m = (MonadTrans (Fix1T t), Monad (t (Fix1T t m) m)) - -instance (MonadFix1T t m, MonadRef m) => MonadRef (Fix1T t m) where - type Ref (Fix1T t m) = Ref m - newRef = lift . newRef - readRef = lift . readRef - writeRef r = lift . writeRef r - -instance (MonadFix1T t m, MonadAtomicRef m) => MonadAtomicRef (Fix1T t m) where - atomicModifyRef r = lift . atomicModifyRef r - instance (MonadFix1T t m, MonadFail (Fix1T t m), MonadFile m) => MonadFile (Fix1T t m) instance (MonadFix1T t m, MonadStore m) => MonadStore (Fix1T t m) where diff --git a/src/Nix/Utils/Fix1.hs b/src/Nix/Utils/Fix1.hs index 9ef62d3ce..2595fefb6 100644 --- a/src/Nix/Utils/Fix1.hs +++ b/src/Nix/Utils/Fix1.hs @@ -1,3 +1,6 @@ +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE ConstraintKinds #-} +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} @@ -16,6 +19,10 @@ import Control.Monad.Fail import Control.Monad ( MonadPlus ) import Control.Monad.Fix ( MonadFix ) import Control.Monad.IO.Class ( MonadIO ) +import Control.Monad.Trans.Class ( MonadTrans + , lift ) +import Control.Monad.Ref ( MonadAtomicRef(..) + , MonadRef(..) ) import Control.Monad.Catch ( MonadCatch , MonadMask , MonadThrow ) @@ -57,6 +64,19 @@ deriving instance MonadMask (t (Fix1T t m) m) => MonadMask (Fix1T t m) deriving instance MonadReader e (t (Fix1T t m) m) => MonadReader e (Fix1T t m) deriving instance MonadState s (t (Fix1T t m) m) => MonadState s (Fix1T t m) + +type MonadFix1T t m = (MonadTrans (Fix1T t), Monad (t (Fix1T t m) m)) + +instance (MonadFix1T t m, MonadRef m) => MonadRef (Fix1T t m) where + type Ref (Fix1T t m) = Ref m + newRef = lift . newRef + readRef = lift . readRef + writeRef r = lift . writeRef r + + +instance (MonadFix1T t m, MonadAtomicRef m) => MonadAtomicRef (Fix1T t m) where + atomicModifyRef r = lift . atomicModifyRef r + {- newtype Flip (f :: i -> j -> *) (a :: j) (b :: i) = Flip { unFlip :: f b a } From d3532a300ab36868cc616d259c887b44594f0f30 Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Fri, 8 Jan 2021 00:28:18 +0200 Subject: [PATCH 11/19] move instance MonadFile Fix1T to the parent --- src/Nix/Render.hs | 6 ++++++ src/Nix/Standard.hs | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Nix/Render.hs b/src/Nix/Render.hs index 0ba390eb1..e059a5e7f 100644 --- a/src/Nix/Render.hs +++ b/src/Nix/Render.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE CPP #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DefaultSignatures #-} @@ -23,6 +24,8 @@ import qualified Data.Set as Set import qualified Data.Text as T import qualified Data.Text.Encoding as T import Data.Void +import Nix.Utils.Fix1 ( Fix1T + , MonadFix1T ) import Nix.Expr.Types.Annotated import Prettyprinter import qualified System.Directory as S @@ -70,6 +73,9 @@ instance MonadFile IO where doesDirectoryExist = S.doesDirectoryExist getSymbolicLinkStatus = S.getSymbolicLinkStatus + +instance (MonadFix1T t m, MonadFail (Fix1T t m), MonadFile m) => MonadFile (Fix1T t m) + posAndMsg :: SourcePos -> Doc a -> ParseError s Void posAndMsg (SourcePos _ lineNo _) msg = FancyError (unPos lineNo) diff --git a/src/Nix/Standard.hs b/src/Nix/Standard.hs index 705af05d9..77e822a8d 100644 --- a/src/Nix/Standard.hs +++ b/src/Nix/Standard.hs @@ -52,8 +52,6 @@ import Nix.Value.Monad import Nix.Var -instance (MonadFix1T t m, MonadFail (Fix1T t m), MonadFile m) => MonadFile (Fix1T t m) - instance (MonadFix1T t m, MonadStore m) => MonadStore (Fix1T t m) where addToStore a b c d = lift $ addToStore a b c d addTextToStore' a b c d = lift $ addTextToStore' a b c d From 0515c5f7f87d1eeb8d5aa95db48087950173a745 Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Fri, 8 Jan 2021 00:29:33 +0200 Subject: [PATCH 12/19] move instance MonadStore Fix1T to the parent --- src/Nix/Effects.hs | 4 ++++ src/Nix/Standard.hs | 6 ------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Nix/Effects.hs b/src/Nix/Effects.hs index e7bffcc01..024205a3e 100644 --- a/src/Nix/Effects.hs +++ b/src/Nix/Effects.hs @@ -74,6 +74,10 @@ class (MonadFile m, traceEffect :: String -> m () +instance (MonadFix1T t m, MonadStore m) => MonadStore (Fix1T t m) where + addToStore a b c d = lift $ addToStore a b c d + addTextToStore' a b c d = lift $ addTextToStore' a b c d + class Monad m => MonadIntrospect m where recursiveSize :: a -> m Word default recursiveSize :: (MonadTrans t, MonadIntrospect m', m ~ t m') => a -> m Word diff --git a/src/Nix/Standard.hs b/src/Nix/Standard.hs index 77e822a8d..538bcc5e7 100644 --- a/src/Nix/Standard.hs +++ b/src/Nix/Standard.hs @@ -52,12 +52,6 @@ import Nix.Value.Monad import Nix.Var -instance (MonadFix1T t m, MonadStore m) => MonadStore (Fix1T t m) where - addToStore a b c d = lift $ addToStore a b c d - addTextToStore' a b c d = lift $ addTextToStore' a b c d - ---------------------------------------------------------------------------------- - newtype StdCited m a = StdCited { _stdCited :: Cited (StdThunk m) (StdCited m) m a } deriving From 6383f1ff6d27d59aab735a51489b07eb6450115c Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Tue, 9 Feb 2021 00:00:35 +0200 Subject: [PATCH 13/19] Expr/Types: m upd --- src/Nix/Expr/Types.hs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Nix/Expr/Types.hs b/src/Nix/Expr/Types.hs index 5df335dbe..60acaf02a 100644 --- a/src/Nix/Expr/Types.hs +++ b/src/Nix/Expr/Types.hs @@ -27,7 +27,7 @@ module Nix.Expr.Types where #ifdef MIN_VERSION_serialise -import qualified Codec.Serialise ( Serialise(decode, encode) ) -- For instance implementation function disamburgation +import qualified Codec.Serialise as Serialise import Codec.Serialise ( Serialise ) #endif import Control.Applicative @@ -35,8 +35,8 @@ import Control.DeepSeq import Control.Monad import Data.Aeson import Data.Aeson.TH +import qualified Data.Binary as Binary import Data.Binary ( Binary ) -import qualified Data.Binary as Bin import Data.Data import Data.Eq.Deriving import Data.Fix @@ -65,8 +65,8 @@ import Nix.Utils import Text.Megaparsec.Pos import Text.Read.Deriving import Text.Show.Deriving -import Type.Reflection ( eqTypeRep ) import qualified Type.Reflection as Reflection +import Type.Reflection ( eqTypeRep ) type VarName = Text @@ -347,16 +347,16 @@ data NKeyName r instance Serialise r => Serialise (NKeyName r) instance Serialise Pos where - encode x = Codec.Serialise.encode (unPos x) - decode = mkPos <$> Codec.Serialise.decode + encode = Serialise.encode . unPos + decode = mkPos <$> Serialise.decode instance Serialise SourcePos where - encode (SourcePos f l c) = Codec.Serialise.encode f <> Codec.Serialise.encode l <> Codec.Serialise.encode c - decode = SourcePos <$> Codec.Serialise.decode <*> Codec.Serialise.decode <*> Codec.Serialise.decode + encode (SourcePos f l c) = Serialise.encode f <> Serialise.encode l <> Serialise.encode c + decode = SourcePos <$> Serialise.decode <*> Serialise.decode <*> Serialise.decode #endif instance Hashable Pos where - hashWithSalt salt x = hashWithSalt salt (unPos x) + hashWithSalt salt = hashWithSalt salt . unPos instance Hashable SourcePos where hashWithSalt salt (SourcePos f l c) = @@ -418,7 +418,7 @@ instance Traversable NKeyName where DynamicKey (Plain str) -> DynamicKey . Plain <$> traverse f str DynamicKey (Antiquoted e ) -> DynamicKey . Antiquoted <$> f e DynamicKey EscapedNewline -> pure $ DynamicKey EscapedNewline - StaticKey key -> pure (StaticKey key) + StaticKey key -> pure $ StaticKey key -- | A selector (for example in a @let@ or an attribute set) is made up -- of strung-together key names. @@ -518,8 +518,8 @@ instance (Binary v, Binary a) => Binary (Antiquoted v a) instance Binary a => Binary (NString a) instance Binary a => Binary (Binding a) instance Binary Pos where - put x = Bin.put (unPos x) - get = mkPos <$> Bin.get + put = Binary.put . unPos + get = mkPos <$> Binary.get instance Binary SourcePos instance Binary a => Binary (NKeyName a) instance Binary a => Binary (Params a) @@ -532,7 +532,7 @@ instance (ToJSON v, ToJSON a) => ToJSON (Antiquoted v a) instance ToJSON a => ToJSON (NString a) instance ToJSON a => ToJSON (Binding a) instance ToJSON Pos where - toJSON x = toJSON (unPos x) + toJSON = toJSON . unPos instance ToJSON SourcePos instance ToJSON a => ToJSON (NKeyName a) instance ToJSON a => ToJSON (Params a) @@ -566,8 +566,8 @@ $(makeTraversals ''NBinaryOp) --x $(makeLenses ''Fix) class NExprAnn ann g | g -> ann where - fromNExpr :: g r -> (NExprF r, ann) - toNExpr :: (NExprF r, ann) -> g r + fromNExpr :: g r -> (NExprF r, ann) + toNExpr :: (NExprF r, ann) -> g r ekey :: NExprAnn ann g @@ -599,7 +599,7 @@ ekey _ _ f e = fromMaybe e <$> f Nothing stripPositionInfo :: NExpr -> NExpr stripPositionInfo = transport phi where - phi (NSet recur binds) = NSet recur (fmap go binds) + phi (NSet recur binds) = NSet recur $ fmap go binds phi (NLet binds body) = NLet (fmap go binds) body phi x = x From fa7aab222445398c62d992bd90fdb22268347b3b Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Tue, 9 Feb 2021 00:22:07 +0200 Subject: [PATCH 14/19] remaining map -> fmap --- main/Repl.hs | 2 +- tests/NixLanguageTests.hs | 4 ++-- tests/ParserTests.hs | 2 +- tests/PrettyParseTests.hs | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/main/Repl.hs b/main/Repl.hs index 03abff344..a35946d33 100644 --- a/main/Repl.hs +++ b/main/Repl.hs @@ -100,7 +100,7 @@ main' iniVal = initState iniVal >>= \s -> flip evalStateT s rcFile = do f <- liftIO $ Data.Text.IO.readFile ".hnixrc" `catch` handleMissing - forM_ (map (words . Data.Text.unpack) $ Data.Text.lines f) $ \case + forM_ (fmap (words . Data.Text.unpack) $ Data.Text.lines f) $ \case ((prefix:command) : xs) | prefix == commandPrefix -> do let arguments = unwords xs optMatcher command options arguments diff --git a/tests/NixLanguageTests.hs b/tests/NixLanguageTests.hs index e132fe613..c479eeb99 100644 --- a/tests/NixLanguageTests.hs +++ b/tests/NixLanguageTests.hs @@ -158,7 +158,7 @@ assertEval _opts files = do Opts.execParserPure Opts.defaultPrefs (nixOptionsInfo time) - (fixup (map Text.unpack (Text.splitOn " " flags'))) + (fixup (fmap Text.unpack (Text.splitOn " " flags'))) of Opts.Failure err -> errorWithoutStackTrace @@ -171,7 +171,7 @@ assertEval _opts files = do _ -> assertFailure $ "Unknown test type " ++ show files where name = - "data/nix/tests/lang/" ++ the (map (takeFileName . dropExtensions) files) + "data/nix/tests/lang/" ++ the (fmap (takeFileName . dropExtensions) files) fixup ("--arg" : x : y : rest) = "--arg" : (x ++ "=" ++ y) : fixup rest fixup ("--argstr" : x : y : rest) = "--argstr" : (x ++ "=" ++ y) : fixup rest diff --git a/tests/ParserTests.hs b/tests/ParserTests.hs index 0439b4075..8df480f6c 100644 --- a/tests/ParserTests.hs +++ b/tests/ParserTests.hs @@ -122,7 +122,7 @@ case_inherit_selector = do case_int_list = assertParseText "[1 2 3]" $ Fix $ NList [ mkInt i | i <- [1,2,3] ] -case_int_null_list = assertParseText "[1 2 3 null 4]" $ Fix (NList (map (Fix . NConstant) [NInt 1, NInt 2, NInt 3, NNull, NInt 4])) +case_int_null_list = assertParseText "[1 2 3 null 4]" $ Fix (NList (fmap (Fix . NConstant) [NInt 1, NInt 2, NInt 3, NNull, NInt 4])) case_mixed_list = do assertParseText "[{a = 3;}.a (if true then null else false) null false 4 [] c.d or null]" $ Fix $ NList diff --git a/tests/PrettyParseTests.hs b/tests/PrettyParseTests.hs index 026be2ae6..3426bfe04 100644 --- a/tests/PrettyParseTests.hs +++ b/tests/PrettyParseTests.hs @@ -148,8 +148,8 @@ normalize = foldFix $ \case NConstant (NFloat n) | n < 0 -> Fix (NUnary NNeg (Fix (NConstant (NFloat (negate n))))) - NSet recur binds -> Fix (NSet recur (map normBinding binds)) - NLet binds r -> Fix (NLet (map normBinding binds) r) + NSet recur binds -> Fix (NSet recur (fmap normBinding binds)) + NLet binds r -> Fix (NLet (fmap normBinding binds) r) NAbs params r -> Fix (NAbs (normParams params) r) @@ -157,7 +157,7 @@ normalize = foldFix $ \case where normBinding (NamedVar path r pos) = NamedVar (NE.map normKey path) r pos - normBinding (Inherit mr names pos) = Inherit mr (map normKey names) pos + normBinding (Inherit mr names pos) = Inherit mr (fmap normKey names) pos normKey (DynamicKey quoted) = DynamicKey (normAntiquotedString quoted) normKey (StaticKey name ) = StaticKey name @@ -220,7 +220,7 @@ prop_prettyparse p = do normalise = unlines . fmap (reverse . dropWhile isSpace . reverse) . lines ldiff :: String -> String -> [Diff [String]] - ldiff s1 s2 = getDiff (map (: []) (lines s1)) (map (: []) (lines s2)) + ldiff s1 s2 = getDiff (fmap (: []) (lines s1)) (fmap (: []) (lines s2)) tests :: TestLimit -> TestTree tests n = testProperty "Pretty/Parse Property" $ withTests n $ property $ do From 0375504a38b53621cdafcfe60f421ab31bac0ee7 Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Tue, 9 Feb 2021 00:33:52 +0200 Subject: [PATCH 15/19] Var: m refactor --- src/Nix/Var.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Nix/Var.hs b/src/Nix/Var.hs index 0b56d98ce..4eaffbecd 100644 --- a/src/Nix/Var.hs +++ b/src/Nix/Var.hs @@ -15,6 +15,7 @@ import Data.STRef import Type.Reflection ((:~:)(Refl)) import Unsafe.Coerce +import Data.Bool ( bool ) type Var m = Ref m @@ -37,7 +38,15 @@ atomicModifyVar = atomicModifyRef --TODO: Upstream GEq instances instance GEq IORef where - a `geq` b = if a == unsafeCoerce b then Just $ unsafeCoerce Refl else Nothing + a `geq` b = + bool + Nothing + (pure $ unsafeCoerce Refl) + (a == unsafeCoerce b ) instance GEq (STRef s) where - a `geq` b = if a == unsafeCoerce b then Just $ unsafeCoerce Refl else Nothing + a `geq` b = + bool + Nothing + (pure $ unsafeCoerce Refl ) + (a == unsafeCoerce b) From fec7032a25e7c6420ce4e08543e5535f0255c61d Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Tue, 9 Feb 2021 01:09:01 +0200 Subject: [PATCH 16/19] Fresh{,.Basic}, Effects: m clean-up --- src/Nix/Effects.hs | 40 ++++++++++++++++++++-------------------- src/Nix/Fresh.hs | 19 +++++++++++-------- src/Nix/Fresh/Basic.hs | 3 ++- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/Nix/Effects.hs b/src/Nix/Effects.hs index 024205a3e..e40778f38 100644 --- a/src/Nix/Effects.hs +++ b/src/Nix/Effects.hs @@ -44,7 +44,7 @@ import qualified System.Info import System.Process import qualified System.Nix.Hash as Store -import qualified System.Nix.Store.Remote as Store +import qualified System.Nix.Store.Remote as Store.Remote import qualified System.Nix.StorePath as Store -- | A path into the nix store @@ -227,11 +227,11 @@ instance MonadHttp IO where class Monad m => MonadPutStr m where - --TODO: Should this be used *only* when the Nix to be evaluated invokes a - --`trace` operation? - putStr :: String -> m () - default putStr :: (MonadTrans t, MonadPutStr m', m ~ t m') => String -> m () - putStr = lift . putStr + --TODO: Should this be used *only* when the Nix to be evaluated invokes a + --`trace` operation? + putStr :: String -> m () + default putStr :: (MonadTrans t, MonadPutStr m', m ~ t m') => String -> m () + putStr = lift . putStr putStrLn :: MonadPutStr m => String -> m () putStrLn = putStr . (<> "\n") @@ -251,20 +251,20 @@ type StorePathSet = HS.HashSet StorePath class Monad m => MonadStore m where - -- | Copy the contents of a local path to the store. The resulting store - -- path is returned. Note: This does not support yet support the expected - -- `filter` function that allows excluding some files. - addToStore :: StorePathName -> FilePath -> RecursiveFlag -> RepairFlag -> m (Either ErrorCall StorePath) - default addToStore :: (MonadTrans t, MonadStore m', m ~ t m') => StorePathName -> FilePath -> RecursiveFlag -> RepairFlag -> m (Either ErrorCall StorePath) - addToStore a b c d = lift $ addToStore a b c d + -- | Copy the contents of a local path to the store. The resulting store + -- path is returned. Note: This does not support yet support the expected + -- `filter` function that allows excluding some files. + addToStore :: StorePathName -> FilePath -> RecursiveFlag -> RepairFlag -> m (Either ErrorCall StorePath) + default addToStore :: (MonadTrans t, MonadStore m', m ~ t m') => StorePathName -> FilePath -> RecursiveFlag -> RepairFlag -> m (Either ErrorCall StorePath) + addToStore a b c d = lift $ addToStore a b c d - -- | Like addToStore, but the contents written to the output path is a - -- regular file containing the given string. - addTextToStore' :: StorePathName -> Text -> Store.StorePathSet -> RepairFlag -> m (Either ErrorCall StorePath) - default addTextToStore' :: (MonadTrans t, MonadStore m', m ~ t m') => StorePathName -> Text -> Store.StorePathSet -> RepairFlag -> m (Either ErrorCall StorePath) - addTextToStore' a b c d = lift $ addTextToStore' a b c d + -- | Like addToStore, but the contents written to the output path is a + -- regular file containing the given string. + addTextToStore' :: StorePathName -> Text -> Store.StorePathSet -> RepairFlag -> m (Either ErrorCall StorePath) + default addTextToStore' :: (MonadTrans t, MonadStore m', m ~ t m') => StorePathName -> Text -> Store.StorePathSet -> RepairFlag -> m (Either ErrorCall StorePath) + addTextToStore' a b c d = lift $ addTextToStore' a b c d -parseStoreResult :: Monad m => String -> (Either String a, [Store.Logger]) -> m (Either ErrorCall a) +parseStoreResult :: Monad m => String -> (Either String a, [Store.Remote.Logger]) -> m (Either ErrorCall a) parseStoreResult name res = case res of (Left msg, logs) -> return $ Left $ ErrorCall $ "Failed to execute '" <> name <> "': " <> msg <> "\n" <> show logs (Right result, _) -> return $ Right result @@ -275,13 +275,13 @@ instance MonadStore IO where Left err -> return $ Left $ ErrorCall $ "String '" <> show name <> "' is not a valid path name: " <> err Right pathName -> do -- TODO: redesign the filter parameter - res <- Store.runStore $ Store.addToStore @'Store.SHA256 pathName path recursive (const False) repair + res <- Store.Remote.runStore $ Store.Remote.addToStore @'Store.SHA256 pathName path recursive (const False) repair parseStoreResult "addToStore" res >>= \case Left err -> return $ Left err Right storePath -> return $ Right $ StorePath $ T.unpack $ T.decodeUtf8 $ Store.storePathToRawFilePath storePath addTextToStore' name text references repair = do - res <- Store.runStore $ Store.addTextToStore name text references repair + res <- Store.Remote.runStore $ Store.Remote.addTextToStore name text references repair parseStoreResult "addTextToStore" res >>= \case Left err -> return $ Left err Right path -> return $ Right $ StorePath $ T.unpack $ T.decodeUtf8 $ Store.storePathToRawFilePath path diff --git a/src/Nix/Fresh.hs b/src/Nix/Fresh.hs index ed5793555..8dbd4ae78 100644 --- a/src/Nix/Fresh.hs +++ b/src/Nix/Fresh.hs @@ -50,14 +50,16 @@ instance MonadTrans (FreshIdT i) where instance MonadBase b m => MonadBase b (FreshIdT i m) where liftBase = FreshIdT . liftBase -instance ( MonadVar m - , Eq i - , Ord i - , Show i - , Enum i - , Typeable i - ) - => MonadThunkId (FreshIdT i m) where +instance + ( MonadVar m + , Eq i + , Ord i + , Show i + , Enum i + , Typeable i + ) + => MonadThunkId (FreshIdT i m) + where type ThunkId (FreshIdT i m) = i freshId = FreshIdT $ do v <- ask @@ -69,6 +71,7 @@ runFreshIdT i m = runReaderT (unFreshIdT m) i -- Orphan instance needed by Infer.hs and Lint.hs -- Since there's no forking, it's automatically atomic. +-- NOTE: MonadAtomicRef (ST s) can be upstreamed to `ref-tf` instance MonadAtomicRef (ST s) where atomicModifyRef r f = do v <- readRef r diff --git a/src/Nix/Fresh/Basic.hs b/src/Nix/Fresh/Basic.hs index be5c20972..6c58538bb 100644 --- a/src/Nix/Fresh/Basic.hs +++ b/src/Nix/Fresh/Basic.hs @@ -20,6 +20,7 @@ import Nix.Value type StdIdT = FreshIdT Int +-- NOTE: These would be removed by: https://github.com/haskell-nix/hnix/pull/804 instance (MonadFail m, MonadFile m) => MonadFile (StdIdT m) instance MonadIntrospect m => MonadIntrospect (StdIdT m) instance MonadStore m => MonadStore (StdIdT m) @@ -45,6 +46,6 @@ instance (MonadEffects t f m, MonadDataContext f m) pathToDefaultNix = lift . pathToDefaultNix @t @f @m derivationStrict v = do i <- FreshIdT ask - p <- lift $ derivationStrict @t @f @m (unliftNValue (runFreshIdT i) v) + p <- lift $ derivationStrict @t @f @m $ unliftNValue (runFreshIdT i) v return $ liftNValue (runFreshIdT i) p traceEffect = lift . traceEffect @t @f @m From ecab803783151b8a8f2de7d7af7758ff9e64ed60 Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Tue, 9 Feb 2021 01:21:20 +0200 Subject: [PATCH 17/19] add back the "OPTIONS_GHC -Wno-orphans" --- src/Nix/Effects.hs | 3 +++ src/Nix/Exec.hs | 2 ++ src/Nix/Expr/Types.hs | 2 +- src/Nix/Fresh.hs | 1 + src/Nix/Fresh/Basic.hs | 1 + src/Nix/Standard.hs | 1 + src/Nix/Var.hs | 1 + 7 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Nix/Effects.hs b/src/Nix/Effects.hs index e40778f38..b44d914b3 100644 --- a/src/Nix/Effects.hs +++ b/src/Nix/Effects.hs @@ -13,6 +13,9 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE UndecidableInstances #-} +{-# OPTIONS_GHC -Wno-orphans #-} + + module Nix.Effects where import Prelude hiding ( putStr diff --git a/src/Nix/Exec.hs b/src/Nix/Exec.hs index 922cffbc3..f3417347f 100644 --- a/src/Nix/Exec.hs +++ b/src/Nix/Exec.hs @@ -15,8 +15,10 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} +{-# OPTIONS_GHC -Wno-orphans #-} {-# OPTIONS_GHC -fno-warn-name-shadowing #-} + module Nix.Exec where import Prelude hiding ( putStr diff --git a/src/Nix/Expr/Types.hs b/src/Nix/Expr/Types.hs index 60acaf02a..ab4ecdfa1 100644 --- a/src/Nix/Expr/Types.hs +++ b/src/Nix/Expr/Types.hs @@ -17,7 +17,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE InstanceSigs #-} - +{-# OPTIONS_GHC -Wno-orphans #-} {-# OPTIONS_GHC -Wno-missing-signatures #-} -- | The Nix expression type and supporting types. diff --git a/src/Nix/Fresh.hs b/src/Nix/Fresh.hs index 8dbd4ae78..8aed021a6 100644 --- a/src/Nix/Fresh.hs +++ b/src/Nix/Fresh.hs @@ -8,6 +8,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} +{-# OPTIONS_GHC -Wno-orphans #-} module Nix.Fresh where diff --git a/src/Nix/Fresh/Basic.hs b/src/Nix/Fresh/Basic.hs index 6c58538bb..e60aa0f34 100644 --- a/src/Nix/Fresh/Basic.hs +++ b/src/Nix/Fresh/Basic.hs @@ -5,6 +5,7 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeSynonymInstances #-} +{-# OPTIONS_GHC -Wno-orphans #-} module Nix.Fresh.Basic where diff --git a/src/Nix/Standard.hs b/src/Nix/Standard.hs index 538bcc5e7..18fc06cac 100644 --- a/src/Nix/Standard.hs +++ b/src/Nix/Standard.hs @@ -12,6 +12,7 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE UndecidableInstances #-} +{-# OPTIONS_GHC -Wno-orphans #-} module Nix.Standard where diff --git a/src/Nix/Var.hs b/src/Nix/Var.hs index 4eaffbecd..f4e67e116 100644 --- a/src/Nix/Var.hs +++ b/src/Nix/Var.hs @@ -3,6 +3,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# OPTIONS_GHC -Wno-orphans #-} module Nix.Var where From e5c34b87cc67a7c4d7d37aeb92e5db1a4adeac8f Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Tue, 9 Feb 2021 02:14:36 +0200 Subject: [PATCH 18/19] Value.Equal: m refactor --- src/Nix/Value/Equal.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Nix/Value/Equal.hs b/src/Nix/Value/Equal.hs index d791765f8..6a54c1feb 100644 --- a/src/Nix/Value/Equal.hs +++ b/src/Nix/Value/Equal.hs @@ -111,8 +111,8 @@ valueFEq -> NValueF p m a -> Bool valueFEq attrsEq eq x y = runIdentity $ valueFEqM - (\x' y' -> Identity (attrsEq x' y')) - (\x' y' -> Identity (eq x' y')) + (\x' y' -> Identity $ attrsEq x' y') + (\x' y' -> Identity $ eq x' y') x y @@ -141,7 +141,7 @@ compareAttrSets -> AttrSet t -> Bool compareAttrSets f eq lm rm = runIdentity - $ compareAttrSetsM (\t -> Identity (f t)) (\x y -> Identity (eq x y)) lm rm + $ compareAttrSetsM (Identity . f) (\x y -> Identity (eq x y)) lm rm valueEqM :: forall t f m From 8c6fb78844f64f4aeb308ea7f5724e501197c4e8 Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Tue, 9 Feb 2021 02:14:53 +0200 Subject: [PATCH 19/19] ChangeLog: annotate instance migration --- ChangeLog.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 0a53072cd..6a2aae6cb 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -23,6 +23,39 @@ * `principledMakeNixStringWithSingletonContext` -> `makeNixStringWithSingletonContext`. * `principledModifyNixContents` -> `modifyNixContents`. + * [(link)](https://github.com/haskell-nix/hnix/pull/805/files): + * Data type: `MonadFix1T t m`: `Nix.Standard` -> `Nix.Utils.Fix1` + * Children found their parents: + * `Binary NAtom`: `Nix.Expr.Types` -> `Nix.Atoms` + * `Eq1 (NValue' t f m a)`: `Nix.Value.Equal` -> `Nix.Value` - instance was TH, become regular derivable + * `Eq1 (NValueF p m)`: `Nix.Value.Equal` -> `Nix.Value` + * `FromJSON NAtom`: `Nix.Expr.Types` -> `Nix.Atoms` + * `ToJSON NAtom`: `Nix.Expr.Types` -> `Nix.Atoms` + * `HasCitations m v (NValue t f m)`: `Nix.Pretty` -> `Nix.Cited` + * `HasCitations m v (NValue' t f m a)`: `Nix.Pretty` -> `Nix.Cited` + * `Hashable1 Binding`: `Nix.Expr.Types` -> `Void` - please, report if it is needed + * `Hashable1 NExprF`: `Nix.Expr.Types` -> `Void` - please, report if it is needed + * `Hashable1 NonEmpty`: `Nix.Expr.Types` -> `Void` - please, report if it is needed + * `MonadAtomicRef (Fix1T t m)`: `Nix.Standard` -> `Nix.Utils.Fix1` + * `MonadEnv (Fix1 t)`: `Nix.Standard` -> `Nix.Efffects` + * `MonadEnv (Fix1T t m)`: `Nix.Standard` -> `Nix.Efffects` + * `MonadExec (Fix1 t)`: `Nix.Standard` -> `Nix.Efffects` + * `MonadExec (Fix1T t m)`: `Nix.Standard` -> `Nix.Efffects` + * `MonadFile (Fix1T t m)`: `Nix.Standard` -> `Nix.Render` + * `MonadHttp (Fix1 t)`: `Nix.Standard` -> `Nix.Efffects` + * `MonadHttp (Fix1T t m)`: `Nix.Standard` -> `Nix.Efffects` + * `MonadInstantiate (Fix1 t)`: `Nix.Standard` -> `Nix.Efffects` + * `MonadInstantiate (Fix1T t m)`: `Nix.Standard` -> `Nix.Efffects` + * `MonadIntrospect (Fix1 t)`: `Nix.Standard` -> `Nix.Efffects` + * `MonadIntrospect (Fix1T t m)`: `Nix.Standard` -> `Nix.Efffects` + * `MonadPaths (Fix1 t)`: `Nix.Standard` -> `Nix.Efffects` + * `MonadPaths (Fix1T t m)`: `Nix.Standard` -> `Nix.Efffects` + * `MonadPutStr (Fix1 t)`: `Nix.Standard` -> `Nix.Effects` + * `MonadPutStr (Fix1T t m)`: `Nix.Standard` -> `Nix.Efffects` + * `MonadRef (Fix1T t m)`: `Nix.Standard` -> `Nix.Utils.Fix1` + * `MonadStore (Fix1T t m)`: `Nix.Standard` -> `Nix.Efffects` + + * Additional: * [(link)](https://github.com/haskell-nix/hnix/commit/7e6cd97bf3288cb584241611fdb25bf85d7e0ba7) `cabal.project`: freed from the `cryptohash-sha512` override, Hackage trustees made a revision. * [(link)](https://github.com/haskell-nix/hnix/pull/824/commits/4422eb10959115f21045f39e302314a77df4b775) To be more approachable for user understanding, the thunk representation in outputs changed from `"" -> ""`.