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

Use microlens package family instead of lens-family-core #2642

Merged
merged 8 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion dhall-docs/dhall-docs.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Library
dhall >= 1.38.0 && < 1.43,
file-embed >= 0.0.10.0 ,
filepath >= 1.4 && < 1.6 ,
lens-family-core >= 1.0.0 && < 2.2 ,
microlens >= 0.4 && < 0.5 ,
lucid >= 2.9.12 && < 2.12,
mmark >= 0.0.7.0 && < 0.8 ,
-- megaparsec follows SemVer: https://github.com/mrkkrp/megaparsec/issues/469#issuecomment-927918469
Expand Down
2 changes: 1 addition & 1 deletion dhall-docs/src/Dhall/Docs/CodeRenderer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import qualified Dhall.Map as Map
import qualified Dhall.Parser
import qualified Dhall.Pretty
import qualified Lens.Family as Lens
import qualified Lens.Micro as Lens
import qualified Prettyprinter as Pretty
import qualified Prettyprinter.Render.Text as Pretty.Text
import qualified Text.Megaparsec.Pos as SourcePos
Expand Down Expand Up @@ -374,7 +374,7 @@

-- calls to `head` and `last` here should never fail since `importLines`
-- have at least one element
let (firstImportLine, lastImportLine) = (head importLines, last importLines)

Check warning on line 377 in dhall-docs/src/Dhall/Docs/CodeRenderer.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest - stack.ghc-9.8.yaml

In the use of ‘head’

Check warning on line 377 in dhall-docs/src/Dhall/Docs/CodeRenderer.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest - stack.ghc-9.8.yaml

In the use of ‘head’
let prefixCols = Text.take (importStartCol - currCol) firstImportLine
let suffixCols = Text.drop (importEndCol - currCol) lastImportLine

Expand Down
2 changes: 1 addition & 1 deletion dhall-json/dhall-json.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Library
dhall >= 1.42.0 && < 1.43,
exceptions >= 0.8.3 && < 0.11,
filepath < 1.6 ,
lens-family-core >= 1.0.0 && < 2.2 ,
microlens >= 0.4.14.0 && < 0.5 ,
optparse-applicative >= 0.14.0.0 && < 0.19,
prettyprinter >= 1.7.0 && < 1.8 ,
scientific >= 0.3.0.0 && < 0.4 ,
Expand Down
5 changes: 2 additions & 3 deletions dhall-json/src/Dhall/JSON.hs
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,11 @@ import qualified Dhall.Core as Core
import qualified Dhall.Import
import qualified Dhall.JSON.Compat as JSON.Compat
import qualified Dhall.Map
import qualified Dhall.Optics
import qualified Dhall.Parser
import qualified Dhall.Pretty
import qualified Dhall.TypeCheck
import qualified Dhall.Util
import qualified Lens.Family as Lens
import qualified Lens.Micro as Lens
import qualified Options.Applicative
import qualified Prettyprinter.Render.Text as Pretty
import qualified System.FilePath
Expand Down Expand Up @@ -1156,7 +1155,7 @@ data SpecialDoubleMode
handleSpecialDoubles
:: SpecialDoubleMode -> Expr s Void -> Either CompileError (Expr s Void)
handleSpecialDoubles specialDoubleMode =
Dhall.Optics.rewriteMOf Core.subExpressions rewrite
Lens.rewriteMOf Core.subExpressions rewrite
where
rewrite =
case specialDoubleMode of
Expand Down
4 changes: 2 additions & 2 deletions dhall-json/src/Dhall/JSONToDhall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ import Data.Void (Void)
import Dhall.Core (Chunks (..), DhallDouble (..), Expr (App))
import Dhall.JSON.Util (pattern FA, pattern V)
import Dhall.Parser (Src)
import Lens.Micro (rewriteOf)
import Options.Applicative (Parser)

import qualified Data.Aeson as Aeson
Expand All @@ -393,7 +394,6 @@ import qualified Dhall.Import
import qualified Dhall.JSON.Compat as JSON.Compat
import qualified Dhall.Lint as Lint
import qualified Dhall.Map as Map
import qualified Dhall.Optics as Optics
import qualified Dhall.Parser
import qualified Dhall.TypeCheck as D
import qualified Options.Applicative as O
Expand Down Expand Up @@ -803,7 +803,7 @@ Right (RecordLit (fromList [("foo",IntegerLit 1)]))
dhallFromJSON
:: Conversion -> ExprX -> Value -> Either CompileError ExprX
dhallFromJSON (Conversion {..}) expressionType =
fmap (Optics.rewriteOf D.subExpressions Lint.useToMap) . loop [] (D.alphaNormalize (D.normalize expressionType))
fmap (rewriteOf D.subExpressions Lint.useToMap) . loop [] (D.alphaNormalize (D.normalize expressionType))
where
loop :: Aeson.Types.JSONPath -> ExprX -> Aeson.Value -> Either CompileError ExprX
-- any ~> Union
Expand Down
2 changes: 1 addition & 1 deletion dhall-nix/dhall-nix.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Library
data-fix < 0.4 ,
dhall >= 1.42 && < 1.43,
hnix >= 0.16 && < 0.18,
lens-family-core >= 1.0.0 && < 2.2 ,
microlens >= 0.4 && < 0.5 ,
neat-interpolation < 0.6 ,
text >= 0.8.0.0 && < 2.2
Exposed-Modules:
Expand Down
6 changes: 2 additions & 4 deletions dhall-nix/src/Dhall/Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}

Expand Down Expand Up @@ -103,7 +102,7 @@ import qualified Data.Text as Text
import Data.Traversable (for)
import Data.Typeable (Typeable)
import Data.Void (Void, absurd)
import Lens.Family (toListOf)
import Lens.Micro (toListOf, rewriteOf)
import Numeric (showHex)
import Data.Char (ord, isDigit, isAsciiLower, isAsciiUpper)

Expand Down Expand Up @@ -151,7 +150,6 @@ import Nix.Expr
import qualified Data.Text
import qualified Dhall.Core
import qualified Dhall.Map
import qualified Dhall.Optics
import qualified Dhall.Pretty
import qualified NeatInterpolation
import qualified Nix
Expand Down Expand Up @@ -336,7 +334,7 @@ dhallToNix e =

-- Even higher-level utility that renames all shadowed references
rewriteShadowed =
Dhall.Optics.rewriteOf Dhall.Core.subExpressions renameShadowed
rewriteOf Dhall.Core.subExpressions renameShadowed

loop (Const _) = return untranslatable
loop (Var (V a 0)) = return (Nix.mkSym (zEncodeSymbol a))
Expand Down
6 changes: 3 additions & 3 deletions dhall-nixpkgs/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ import Dhall.Crypto (SHA256Digest (..))
import Dhall.Import (Status (..), stack)
import Dhall.Parser (Src)
import GHC.Generics (Generic)
import Lens.Family.State.Strict (zoom)
import Lens.Micro (rewriteOf)
import Lens.Micro.Mtl (zoom)
import Network.URI (URI (..), URIAuth (..))
import Nix.Expr.Shorthands ((@.), (@@))
import Nix.Expr.Types (NExpr)
Expand Down Expand Up @@ -117,7 +118,6 @@ import qualified Data.Text.Encoding as Text.Encoding
import qualified Data.Text.IO as Text.IO
import qualified Dhall.Core
import qualified Dhall.Import
import qualified Dhall.Optics
import qualified Dhall.Parser
import qualified GHC.IO.Encoding
import qualified NeatInterpolation
Expand Down Expand Up @@ -341,7 +341,7 @@ findExternalDependencies expression = do

let rewrittenExpression :: Expr Src Import
rewrittenExpression =
Dhall.Optics.rewriteOf Dhall.Core.subExpressions pickAlt expression
rewriteOf Dhall.Core.subExpressions pickAlt expression

import_ <- lift (Turtle.select (Foldable.toList rewrittenExpression))

Expand Down
3 changes: 2 additions & 1 deletion dhall-nixpkgs/dhall-nixpkgs.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Executable dhall-to-nixpkgs
, dhall >= 1.42.0 && < 1.43
, foldl < 1.5
, hnix >= 0.10.1 && < 0.18
, lens-family-core >= 1.0.0 && < 2.2
, microlens >= 0.4 && < 0.5
, microlens-mtl >= 0.1 && < 0.3
-- megaparsec follows SemVer: https://github.com/mrkkrp/megaparsec/issues/469#issuecomment-927918469
, megaparsec >= 7.0.0 && < 10
, mmorph < 1.3
Expand Down
1 change: 1 addition & 0 deletions dhall-openapi/dhall-openapi.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Library
containers >= 0.5.8.0 && < 0.8 ,
dhall >= 1.38.0 && < 1.43 ,
prettyprinter >= 1.7.0 && < 1.8 ,
microlens >= 0.4 && < 0.5 ,
scientific >= 0.3.0.0 && < 0.4 ,
sort >= 1.0 && < 1.1 ,
text >= 0.11.1.0 && < 2.2 ,
Expand Down
14 changes: 7 additions & 7 deletions dhall-openapi/src/Dhall/Kubernetes/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import GHC.Generics (Generic, Rep)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map as Map
import qualified Data.Map.Strict as Data.Map
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
Expand All @@ -32,8 +33,7 @@ import qualified Data.Text as Text
import qualified Data.Tuple as Tuple
import qualified Dhall.Core as Dhall
import qualified Dhall.Map
import qualified Dhall.Optics
import qualified Data.Map as Map
import qualified Lens.Micro as Lens

modelsToText :: ModelHierarchy -> [Text]
modelsToText = List.map (\ (ModelName unModelName) -> unModelName)
Expand Down Expand Up @@ -141,7 +141,7 @@ mergeNoConflicts :: (Ord k, Eq a, Show a, Show k) => (a -> a -> Bool) -> Data.Ma
mergeNoConflicts canMerge = Data.Map.unionWithKey
(\key left right ->
if canMerge left right
then left
then left
else error ("Cannot merge differing values " ++ show left ++ " and " ++ show right ++ " for key " ++ show key))

{- | Extract the 'ModelName' to be used when splitting a definition.
Expand All @@ -164,7 +164,7 @@ guessModelNameForSplit models definition = ModelName <$> ((<>) <$> toPrepend <*>
'modelsToPath'. If a 'ModelName' is provided as a value for the given path, it will be returned (to be then used as
the 'ModelName' for the nested definition. If no 'ModelName' is provided, 'guessModelNameForSplit' will try to guess.
If that fails, 'Nothing' will be returned such that no split will be done by 'toTypes'

Currently not all split points in for nested definitions are supported (in fact only types with a properties
attribute are currently supported).
-}
Expand Down Expand Up @@ -215,7 +215,7 @@ toTypes' prefixMap typeSplitter preferNaturalInt natIntExceptions definitions to
(expr, leftOverDefs) = (convertToType (modelHierarchy ++ [k]) v (isException /= preferNaturalInt))

(newDefs, modelMap) = Data.Map.mapAccumWithKey (convertAndAccumWithKey []) Data.Map.empty definitions

kvList = Dhall.App Dhall.List $ Dhall.Record $ Dhall.Map.fromList
[ ("mapKey", Dhall.makeRecordField Dhall.Text), ("mapValue", Dhall.makeRecordField Dhall.Text) ]

Expand All @@ -233,7 +233,7 @@ toTypes' prefixMap typeSplitter preferNaturalInt natIntExceptions definitions to
shouldBeRequired hierarchy field = Set.member field requiredNames
where
requiredNames = requiredFields hierarchy (required definition)

(newPropDefs, propModelMap) = Data.Map.mapAccumWithKey (convertAndAccumWithKey modelHierarchy) Data.Map.empty props

(required', optional') = Data.Map.partitionWithKey
Expand Down Expand Up @@ -325,7 +325,7 @@ toDefault prefixMap definitions modelName = go
let expression = Dhall.App Dhall.None _T

let adjustedExpression =
Dhall.Optics.transformOf
Lens.transformOf
Dhall.subExpressions
adjustImport
expression
Expand Down
4 changes: 2 additions & 2 deletions dhall/dhall.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ Common common
haskeline >= 0.7.2.1 && < 0.9 ,
hashable >= 1.2 && < 1.6 ,
indexed-traversable < 0.2 ,
lens-family-core >= 1.0.0 && < 2.2 ,
microlens >= 0.4.14.0 && < 0.5 ,
microlens-mtl >= 0.1 && < 0.3 ,
-- megaparsec follows SemVer: https://github.com/mrkkrp/megaparsec/issues/469#issuecomment-927918469
megaparsec >= 8 && < 10 ,
mmorph < 1.3 ,
Expand All @@ -241,7 +242,6 @@ Common common
prettyprinter >= 1.7.0 && < 1.8 ,
prettyprinter-ansi-terminal >= 1.1.2 && < 1.2 ,
pretty-simple < 4.2 ,
profunctors >= 3.1.2 && < 5.7 ,
repline >= 0.4.0.0 && < 0.5 ,
serialise >= 0.2.0.0 && < 0.3 ,
scientific >= 0.3.0.0 && < 0.4 ,
Expand Down
81 changes: 33 additions & 48 deletions dhall/src/Dhall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ import Dhall.Parser (Src (..))
import Dhall.Syntax (Expr (..), Import)
import Dhall.TypeCheck (DetailedTypeError (..), TypeError)
import GHC.Generics
import Lens.Family (LensLike', view)
import Lens.Micro (Lens', lens)
import Lens.Micro.Extras (view)
import Prelude hiding (maybe, sequence)
import System.FilePath (takeDirectory)

Expand All @@ -83,7 +84,7 @@ import qualified Dhall.Parser
import qualified Dhall.Pretty.Internal
import qualified Dhall.Substitution
import qualified Dhall.TypeCheck
import qualified Lens.Family
import qualified Lens.Micro as Lens

import Dhall.Marshal.Decode
import Dhall.Marshal.Encode
Expand Down Expand Up @@ -111,22 +112,16 @@ defaultInputSettings = InputSettings
-- | Access the directory to resolve imports relative to.
--
-- @since 1.16
rootDirectory
:: (Functor f)
=> LensLike' f InputSettings FilePath
rootDirectory k s =
fmap (\x -> s { _rootDirectory = x }) (k (_rootDirectory s))
rootDirectory :: Lens' InputSettings FilePath
rootDirectory = lens _rootDirectory (\s x -> s { _rootDirectory = x })

-- | Access the name of the source to report locations from; this is
-- only used in error messages, so it's okay if this is a best guess
-- or something symbolic.
--
-- @since 1.16
sourceName
:: (Functor f)
=> LensLike' f InputSettings FilePath
sourceName k s =
fmap (\x -> s { _sourceName = x}) (k (_sourceName s))
sourceName :: Lens' InputSettings FilePath
sourceName = lens _sourceName (\s x -> s { _sourceName = x})

-- | @since 1.16
data EvaluateSettings = EvaluateSettings
Expand All @@ -152,59 +147,49 @@ defaultEvaluateSettings = EvaluateSettings
--
-- @since 1.16
startingContext
:: (Functor f, HasEvaluateSettings s)
=> LensLike' f s (Dhall.Context.Context (Expr Src Void))
startingContext = evaluateSettings . l
where
l :: (Functor f)
=> LensLike' f EvaluateSettings (Dhall.Context.Context (Expr Src Void))
l k s = fmap (\x -> s { _startingContext = x}) (k (_startingContext s))
:: (HasEvaluateSettings s)
=> Lens' s (Dhall.Context.Context (Expr Src Void))
startingContext =
evaluateSettings
. lens _startingContext (\s x -> s { _startingContext = x})

-- | Access the custom substitutions.
--
-- @since 1.30
substitutions
:: (Functor f, HasEvaluateSettings s)
=> LensLike' f s (Dhall.Substitution.Substitutions Src Void)
substitutions = evaluateSettings . l
where
l :: (Functor f)
=> LensLike' f EvaluateSettings (Dhall.Substitution.Substitutions Src Void)
l k s = fmap (\x -> s { _substitutions = x }) (k (_substitutions s))
:: (HasEvaluateSettings s)
=> Lens' s (Dhall.Substitution.Substitutions Src Void)
substitutions =
evaluateSettings
. lens _substitutions (\s x -> s { _substitutions = x })

-- | Access the custom normalizer.
--
-- @since 1.16
normalizer
:: (Functor f, HasEvaluateSettings s)
=> LensLike' f s (Maybe (Core.ReifiedNormalizer Void))
normalizer = evaluateSettings . l
where
l :: (Functor f)
=> LensLike' f EvaluateSettings (Maybe (Core.ReifiedNormalizer Void))
l k s = fmap (\x -> s { _normalizer = x }) (k (_normalizer s))
:: (HasEvaluateSettings s)
=> Lens' s (Maybe (Core.ReifiedNormalizer Void))
normalizer =
evaluateSettings
. lens _normalizer (\s x -> s { _normalizer = x })

-- | Access the HTTP manager initializer.
--
-- @since 1.36
newManager
:: (Functor f, HasEvaluateSettings s)
=> LensLike' f s (IO Dhall.Import.Manager)
newManager = evaluateSettings . l
where
l :: (Functor f)
=> LensLike' f EvaluateSettings (IO Dhall.Import.Manager)
l k s = fmap (\x -> s { _newManager = x }) (k (_newManager s))
:: (HasEvaluateSettings s)
=> Lens' s (IO Dhall.Import.Manager)
newManager =
evaluateSettings
. lens _newManager (\s x -> s { _newManager = x })

-- | @since 1.16
class HasEvaluateSettings s where
evaluateSettings
:: (Functor f)
=> LensLike' f s EvaluateSettings
evaluateSettings :: Lens' s EvaluateSettings

instance HasEvaluateSettings InputSettings where
evaluateSettings k s =
fmap (\x -> s { _evaluateSettings = x }) (k (_evaluateSettings s))
evaluateSettings =
lens _evaluateSettings (\s x -> s { _evaluateSettings = x })

instance HasEvaluateSettings EvaluateSettings where
evaluateSettings = id
Expand Down Expand Up @@ -278,9 +263,9 @@ resolveAndStatusWithSettings settings expression = do
let EvaluateSettings{..} = _evaluateSettings

let transform =
Lens.Family.set Dhall.Import.substitutions _substitutions
. Lens.Family.set Dhall.Import.normalizer _normalizer
. Lens.Family.set Dhall.Import.startingContext _startingContext
Lens.set Dhall.Import.substitutions _substitutions
. Lens.set Dhall.Import.normalizer _normalizer
. Lens.set Dhall.Import.startingContext _startingContext

let status = transform (Dhall.Import.emptyStatusWithManager _newManager _rootDirectory)

Expand Down
2 changes: 1 addition & 1 deletion dhall/src/Dhall/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import Dhall.Pretty.Internal
import Dhall.Src (Src (..))
import Dhall.Syntax
import Instances.TH.Lift ()
import Lens.Family (over)
import Lens.Micro (over)
import Prettyprinter (Pretty)

import qualified Control.Exception
Expand Down
Loading
Loading