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

Replace Data.Map with Data.Map.Strict #4675

Merged
merged 2 commits into from
Dec 7, 2022
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
4 changes: 2 additions & 2 deletions STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ Unqualified types (i.e. `Map` vs. `M.Map`) look pretty good and not so ugly.
Prefer two-line imports for such standard containers.

```haskell
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
```

### Data Declarations
Expand Down
44 changes: 22 additions & 22 deletions bench/locli/src/Cardano/Unlog/LogObject.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@

module Cardano.Unlog.LogObject (module Cardano.Unlog.LogObject) where

import Prelude (head, id, show, unzip3)
import Cardano.Prelude hiding (Text, head, show)

import Control.Monad (fail)
import Data.Aeson qualified as AE
import Data.Aeson.KeyMap qualified as KeyMap
import Data.Aeson.Types (Parser)
import Data.Aeson.Key qualified as Aeson
import Data.ByteString.Lazy qualified as LBS
import Data.Text qualified as LText
import Data.Text.Short qualified as Text
import Data.Text.Short (ShortText, fromText, toText)
import Data.Map qualified as Map
import Data.Vector (Vector)
import Data.Vector qualified as V

import Cardano.Logging.Resources.Types

import Cardano.Analysis.API.Ground
import Cardano.Util

import Data.Accum (zeroUTCTime)
import Cardano.Prelude hiding (Text, head, show)
import Prelude (head, id, show, unzip3)

import Control.Monad (fail)
import qualified Data.Aeson as AE
import qualified Data.Aeson.Key as Aeson
import qualified Data.Aeson.KeyMap as KeyMap
import Data.Aeson.Types (Parser)
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Map.Strict as Map
import qualified Data.Text as LText
import Data.Text.Short (ShortText, fromText, toText)
import qualified Data.Text.Short as Text
import Data.Vector (Vector)
import qualified Data.Vector as V

import Cardano.Logging.Resources.Types

import Cardano.Analysis.API.Ground
import Cardano.Util

import Data.Accum (zeroUTCTime)


type Text = ShortText
Expand Down
18 changes: 9 additions & 9 deletions bench/trace-analyzer/src/Cardano/Tracer/Analyze/Process.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ module Cardano.Tracer.Analyze.Process
, extractNamespace
) where

import Cardano.Tracer.Analyze.Types (FileDBM (..), LineNumber)
import Cardano.Tracer.Analyze.Types (FileDBM (..), LineNumber)

import qualified Data.Aeson as AE
import qualified Data.Aeson.KeyMap as AE
import qualified Data.Aeson as AE
import qualified Data.Aeson.KeyMap as AE
import qualified Data.Attoparsec.ByteString.Char8 as Atto
import qualified Data.ByteString.Char8 as BS
import Data.Either (partitionEithers)
import Data.Foldable (foldl')
import qualified Data.Map as Map
import qualified Data.Text as Txt
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as BS
import Data.Either (partitionEithers)
import Data.Foldable (foldl')
import qualified Data.Map.Strict as Map
import qualified Data.Text as Txt
import qualified Data.Vector as V

parseAndPreprocess :: FilePath -> IO FileDBM
parseAndPreprocess fp = do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Control.Monad (when)
import qualified Data.Aeson as AE
import Data.ByteString.Lazy (toStrict)
import Data.List (nub, (\\))
import qualified Data.Map as Map
import qualified Data.Map.Strict as Map
import Data.Text (Text, drop, isPrefixOf, unpack)
import Data.Text.Encoding (decodeUtf8)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Codec.Serialise (DeserialiseFailure)
import Control.Concurrent.Class.MonadSTM.Strict (newTVarIO)
import Control.Monad.Class.MonadTimer (MonadTimer, threadDelay)
import Data.ByteString.Lazy (ByteString)
import qualified Data.Map as Map
import qualified Data.Map.Strict as Map
import Data.Proxy (Proxy (..))
import Network.Socket (AddrInfo (..))
import System.Random (newStdGen)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{-# LANGUAGE ScopedTypeVariables #-}
module Cardano.Benchmarking.PlutusExample
where
import qualified Data.Map as Map
import qualified Data.Map.Strict as Map
import Prelude

import Control.Monad.Trans.Except
Expand Down
23 changes: 11 additions & 12 deletions bench/tx-generator/src/Cardano/Benchmarking/Script/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,27 @@ module Cardano.Benchmarking.Script.Env (
, setEnvWallets
) where

import Prelude
import qualified Data.Text as Text
import Data.Map (Map)
import qualified Data.Map as Map
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Control.Monad.Trans.Except
import Control.Monad.Trans.RWS.Strict (RWST)
import qualified Control.Monad.Trans.RWS.Strict as RWS
import "contra-tracer" Control.Tracer (traceWith)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import qualified Data.Text as Text
import Prelude

import qualified Cardano.Benchmarking.LogTypes as Tracer
import Ouroboros.Network.NodeToClient (IOManager)
import Cardano.Node.Protocol.Types (SomeConsensusProtocol)
import Cardano.Benchmarking.GeneratorTx
import Cardano.Benchmarking.Wallet
import Cardano.Benchmarking.OuroborosImports(NetworkId,
PaymentKey, ShelleyGenesis, SigningKey,
StandardShelley)
import qualified Cardano.Benchmarking.LogTypes as Tracer
import Cardano.Benchmarking.OuroborosImports (NetworkId, PaymentKey, ShelleyGenesis,
SigningKey, StandardShelley)
import Cardano.Benchmarking.Script.Types
import Cardano.Benchmarking.Wallet
import Cardano.Node.Protocol.Types (SomeConsensusProtocol)
import Ouroboros.Network.NodeToClient (IOManager)

import Cardano.TxGenerator.Types (TxGenError(..))
import Cardano.TxGenerator.Types (TxGenError (..))

data Env = Env { protoParams :: Maybe ProtocolParameterMode
, benchTracers :: Maybe Tracer.BenchTracers
Expand Down
4 changes: 2 additions & 2 deletions bench/tx-generator/src/Cardano/Benchmarking/Tracer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ import GHC.Generics
import Data.Aeson as A
import qualified Data.Aeson.KeyMap as KeyMap
import Data.Kind
import qualified Data.Map as Map
import qualified Data.Map.Strict as Map

import Data.Proxy
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Time.Clock

import Ouroboros.Network.IOManager (IOManager)
import Trace.Forward.Utils.DataPoint
import Trace.Forward.Utils.TraceObject
import Ouroboros.Network.IOManager (IOManager)

import Cardano.Api
import Cardano.Logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Cardano.TxGenerator.Setup.Plutus
)
where

import qualified Data.Map as Map
import qualified Data.Map.Strict as Map

import Control.Monad.Trans.Except
import Control.Monad.Trans.Except.Extra
Expand Down
4 changes: 2 additions & 2 deletions cardano-api/src/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ import qualified Data.Array as Array
import Data.Bifunctor (bimap, first)
import qualified Data.ByteString as BS
import Data.ByteString.Short (ShortByteString)
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (catMaybes, fromMaybe, maybeToList)
import Data.Ratio
import Data.Set (Set)
Expand Down
4 changes: 2 additions & 2 deletions cardano-api/src/Cardano/Api/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ import Data.Aeson.Types (Parser)
import Data.Bifunctor (bimap, first)
import qualified Data.ByteString.Lazy as LBS
import qualified Data.HashMap.Strict as HMS
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (mapMaybe)
import Data.Set (Set)
import qualified Data.Set as Set
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Run/Validate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Cardano.Api
import Cardano.Api.Shelley

import Data.Bifunctor (first)
import qualified Data.Map as Map
import qualified Data.Map.Strict as Map
import Data.Maybe
import qualified Data.Text as Text

Expand Down
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/Node/Configuration/Logging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Control.Exception.Safe (MonadCatch)
import Control.Monad.Trans.Except.Extra (catchIOExceptT)
import "contra-tracer" Control.Tracer
import Data.List (nub)
import qualified Data.Map as Map
import qualified Data.Map.Strict as Map
import Data.Text (pack)
import Data.Time.Clock (UTCTime, getCurrentTime)
import Data.Version (showVersion)
Expand Down
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/Node/Startup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import qualified Cardano.Api as Api
import Prelude

import Data.Aeson (FromJSON, ToJSON)
import Data.Map (Map)
import Data.Map.Strict (Map)
import Data.Monoid (Last (..), getLast)
import Data.Text (Text, pack)
import Data.Time.Clock (NominalDiffTime, UTCTime)
Expand Down
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/Node/Tracing/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Prelude

import "contra-tracer" Control.Tracer (traceWith)
import "trace-dispatcher" Control.Tracer (nullTracer)
import qualified Data.Map as Map
import qualified Data.Map.Strict as Map
import Data.Maybe (fromMaybe)
import Data.Time.Clock (getCurrentTime)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Cardano.Node.Tracing.DefaultTraceConfig
( defaultCardanoConfig
) where

import qualified Data.Map.Strict as Map
import Prelude
import qualified Data.Map as Map

import Cardano.Logging

Expand Down
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Prelude

import Data.Aeson (ToJSON (..), Value (..), (.=))
import Data.List (intercalate)
import qualified Data.Map as Map
import qualified Data.Map.Strict as Map
import Data.Text (Text, pack)
import Data.Time (getCurrentTime)
import Data.Time.Clock.POSIX (POSIXTime, utcTimeToPOSIXSeconds)
Expand Down
14 changes: 7 additions & 7 deletions cardano-node/src/Cardano/Tracing/Tracers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Codec.CBOR.Read (DeserialiseFailure)
import Data.Aeson (ToJSON (..), Value (..))
import Data.IntPSQ (IntPSQ)
import qualified Data.IntPSQ as Pq
import qualified Data.Map.Strict as SMap
import qualified Data.Map.Strict as Map
import qualified Data.Text as Text
import Data.Time (NominalDiffTime, UTCTime)
import qualified System.Metrics.Counter as Counter
Expand Down Expand Up @@ -580,38 +580,38 @@ traceI tr meta msg i = traceNamedObject tr (meta, LogValue msg (PureI (fromInteg
sendEKGDirectCounter :: EKGDirect -> Text -> IO ()
sendEKGDirectCounter ekgDirect name = do
modifyMVar_ (ekgCounters ekgDirect) $ \registeredMap -> do
case SMap.lookup name registeredMap of
case Map.lookup name registeredMap of
Just counter -> do
Counter.inc counter
pure registeredMap
Nothing -> do
counter <- EKG.getCounter name (ekgServer ekgDirect)
Counter.inc counter
pure $ SMap.insert name counter registeredMap
pure $ Map.insert name counter registeredMap

sendEKGDirectInt :: Integral a => EKGDirect -> Text -> a -> IO ()
sendEKGDirectInt ekgDirect name val = do
modifyMVar_ (ekgGauges ekgDirect) $ \registeredMap -> do
case SMap.lookup name registeredMap of
case Map.lookup name registeredMap of
Just gauge -> do
Gauge.set gauge (fromIntegral val)
pure registeredMap
Nothing -> do
gauge <- EKG.getGauge name (ekgServer ekgDirect)
Gauge.set gauge (fromIntegral val)
pure $ SMap.insert name gauge registeredMap
pure $ Map.insert name gauge registeredMap

sendEKGDirectDouble :: EKGDirect -> Text -> Double -> IO ()
sendEKGDirectDouble ekgDirect name val = do
modifyMVar_ (ekgLabels ekgDirect) $ \registeredMap -> do
case SMap.lookup name registeredMap of
case Map.lookup name registeredMap of
Just label -> do
Label.set label (Text.pack (show val))
pure registeredMap
Nothing -> do
label <- EKG.getLabel name (ekgServer ekgDirect)
Label.set label (Text.pack (show val))
pure $ SMap.insert name label registeredMap
pure $ Map.insert name label registeredMap

--------------------------------------------------------------------------------
-- Consensus Tracers
Expand Down
8 changes: 4 additions & 4 deletions cardano-testnet/src/Testnet/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module Testnet.Cardano
, cardanoTestnet
) where

import Prelude
import Control.Monad
import Control.Monad.IO.Class (liftIO)
import Data.Aeson ((.=))
Expand All @@ -29,14 +28,15 @@ import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..))
import Hedgehog.Extras.Stock.Time (formatIso8601, showUTCTimeSeconds)
import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter (..))
import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint (..))
import Prelude
import System.FilePath.Posix ((</>))

import qualified Cardano.Node.Configuration.Topology as NonP2P
import qualified Cardano.Node.Configuration.TopologyP2P as P2P
import qualified Data.Aeson as J
import qualified Data.HashMap.Lazy as HM
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Map.Strict as M
import qualified Data.Time.Clock as DTC
import qualified Hedgehog.Extras.Stock.Aeson as J
import qualified Hedgehog.Extras.Stock.IO.Network.Socket as IO
Expand All @@ -52,8 +52,8 @@ import qualified System.Info as OS
import qualified Util.Assert as H
import qualified Util.Process as H
import Util.Process (execCli_)
import Util.Runtime as TR (NodeLoggingFormat (..), PaymentKeyPair (..), PoolNode (PoolNode),
PoolNodeKeys (..), TestnetRuntime (..), startNode)
import Util.Runtime as TR (NodeLoggingFormat (..), PaymentKeyPair (..),
PoolNode (PoolNode), PoolNodeKeys (..), TestnetRuntime (..), startNode)

import qualified Testnet.Conf as H

Expand Down
16 changes: 8 additions & 8 deletions cardano-testnet/src/Testnet/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ module Testnet.Shelley
, hprop_testnet_pause
) where

import Prelude
import Control.Monad
import Control.Monad.IO.Class (MonadIO(liftIO))
import Control.Monad.Trans.Resource (MonadResource(liftResourceT), resourceForkIO)
import Data.Aeson (Value, ToJSON(toJSON))
import Control.Monad.IO.Class (MonadIO (liftIO))
import Control.Monad.Trans.Resource (MonadResource (liftResourceT), resourceForkIO)
import Data.Aeson (ToJSON (toJSON), Value)
import Data.ByteString.Lazy (ByteString)
import Data.Functor
import Data.List ((\\))
import Data.Maybe
import Data.String
import Data.Time.Clock (UTCTime)
import Hedgehog.Extras.Stock.Aeson (rewriteObject)
import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket(..))
import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter(..))
import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint(..))
import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..))
import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter (..))
import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint (..))
import Prelude
import System.FilePath.Posix ((</>))

import qualified Cardano.Node.Configuration.Topology as NonP2P
Expand All @@ -35,7 +35,7 @@ import qualified Control.Concurrent as IO
import qualified Data.Aeson as J
import qualified Data.HashMap.Lazy as HM
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Map.Strict as M
import qualified Data.Time.Clock as DTC
import qualified Hedgehog as H
import qualified Hedgehog.Extras.Stock.IO.File as IO
Expand Down
Loading