Skip to content

Commit

Permalink
Fix limitRecursionBytes for infinite Value's
Browse files Browse the repository at this point in the history
Since infinite values take infinitely long to encode, we can't first
check whether the full value fits into maxBytes. We need to approach the
limit from below instead.
  • Loading branch information
infinisil committed Apr 6, 2021
1 parent 16cf158 commit b85f669
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions morpho-checkpoint-node/src/Morpho/Tracing/Verbosity.hs
Expand Up @@ -30,9 +30,7 @@ limitRecursion _ v = (Any False, v)
-- longer than @maxBytes@. In case @'limitRecursion' minRecursion value@ is
-- already longer than @maxBytes@, it is returned despite that.
limitRecursionBytes :: Int -> Int64 -> Value -> Maybe Value
limitRecursionBytes minRecursion maxBytes value
| atMostMaxBytes value = Just value
| otherwise = lastMay satisfiedLevels
limitRecursionBytes minRecursion maxBytes value = lastMay satisfiedLevels
where
-- Infinite list of Values filtered with an increasing recursion level,
-- annotated with whether they are filtered at all
Expand All @@ -50,7 +48,7 @@ limitRecursionBytes minRecursion maxBytes value
-- A finite list of Values filtered with an increasing recursion level,
-- limited to the Values whose JSON encoding doesn't exceed maxBytes
satisfiedLevels :: [Value]
satisfiedLevels = takeWhile atMostMaxBytes effectiveLevels
satisfiedLevels = takeWhile atMostMaxBytes (effectiveLevels ++ [value])

-- Whether the given Value doesn't exceed @maxBytes@ bytes when encoded
-- as JSON
Expand Down

0 comments on commit b85f669

Please sign in to comment.