diff --git a/hledger-lib/Hledger/Data/Types.hs b/hledger-lib/Hledger/Data/Types.hs index ba4e899e5..177a276be 100644 --- a/hledger-lib/Hledger/Data/Types.hs +++ b/hledger-lib/Hledger/Data/Types.hs @@ -34,6 +34,7 @@ module Hledger.Data.Types ( where import GHC.Generics (Generic) +import Control.DeepSeq (NFData(..)) import Data.Bifunctor (first) import Data.Decimal (Decimal, DecimalRaw(..)) import Data.Default (Default(..)) @@ -762,3 +763,39 @@ data Ledger = Ledger { ljournal :: Journal ,laccounts :: [Account] } deriving (Generic) + +instance NFData AccountAlias +instance NFData AccountDeclarationInfo +instance NFData AccountType +instance NFData Amount +instance NFData AmountCost +instance NFData AmountPrecision +instance NFData AmountStyle +instance NFData BalanceAssertion +instance NFData Commodity +instance NFData DateSpan +instance NFData DigitGroupStyle +instance NFData EFDay +instance NFData Interval +instance NFData Journal +instance NFData MarketPrice +instance NFData MixedAmount +instance NFData MixedAmountKey +instance NFData Rounding +instance NFData PayeeDeclarationInfo +instance NFData PeriodicTransaction +instance NFData PostingType +instance NFData PriceDirective +instance NFData Side +instance NFData Status +instance NFData TagDeclarationInfo +instance NFData TimeclockCode +instance NFData TimeclockEntry +instance NFData TMPostingRule +instance NFData Transaction +instance NFData TransactionModifier + +instance NFData Posting where + -- Do not call rnf on the parent transaction to avoid recursive loops + rnf (Posting d d2 s n a c t ta b mt op) = + rnf d `seq` rnf d2 `seq` rnf s `seq` rnf n `seq` rnf a `seq` rnf c `seq` rnf t `seq` rnf ta `seq` rnf b `seq` mt `seq` rnf op `seq` () diff --git a/hledger-lib/Hledger/Utils/Regex.hs b/hledger-lib/Hledger/Utils/Regex.hs index 052b1e5c6..bbb3cdefe 100644 --- a/hledger-lib/Hledger/Utils/Regex.hs +++ b/hledger-lib/Hledger/Utils/Regex.hs @@ -64,6 +64,7 @@ module Hledger.Utils.Regex ( ) where +import Control.DeepSeq (NFData(..), rwhnf) import Control.Monad (foldM) import Data.Aeson (ToJSON(..), Value(String)) import Data.Array ((!), elems, indices) @@ -129,6 +130,8 @@ instance RegexContext Regexp String String where match = match . reCompiled matchM = matchM . reCompiled +instance NFData Regexp where rnf = rwhnf + -- Convert a Regexp string to a compiled Regex, or return an error message. toRegex :: Text -> Either RegexError Regexp toRegex = memo $ \s -> mkRegexErr s (Regexp s <$> makeRegexM (T.unpack s)) -- Have to unpack here because Text instance in regex-tdfa only appears in 1.3.1