Skip to content

Commit

Permalink
Fix bug in definition of apSubstMaybe. Fixes #894.
Browse files Browse the repository at this point in the history
We also needed to rewrite `anyJust2` to make it more strict,
to avoid reintroducing the space leak of issue #888.
  • Loading branch information
Brian Huffman committed Sep 23, 2020
1 parent ae4406d commit c0f6d1c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/Cryptol/TypeCheck/Subst.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import Cryptol.TypeCheck.TypeMap
import qualified Cryptol.TypeCheck.SimpType as Simp
import qualified Cryptol.TypeCheck.SimpleSolver as Simp
import Cryptol.Utils.Panic(panic)
import Cryptol.Utils.Misc(anyJust)
import Cryptol.Utils.Misc (anyJust, anyJust2)

-- | A 'Subst' value represents a substitution that maps each 'TVar'
-- to a 'Type'.
Expand Down Expand Up @@ -237,8 +237,7 @@ apSubstMaybe su ty =
_ -> Just (TCon t ss)

TUser f ts t ->
do t1 <- apSubstMaybe su t
let !ts1 = fmap' (apSubst su) ts
do (ts1, t1) <- anyJust2 (anyJust (apSubstMaybe su)) (apSubstMaybe su) (ts, t)
Just (TUser f ts1 t1)

TRec fs -> TRec `fmap` (anyJust (apSubstMaybe su) fs)
Expand Down
5 changes: 3 additions & 2 deletions src/Cryptol/Utils/Misc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
module Cryptol.Utils.Misc where

import MonadLib
import Data.Maybe(fromMaybe)

import Prelude ()
import Prelude.Compat
Expand All @@ -32,4 +31,6 @@ anyJust2 :: (a -> Maybe a) -> (b -> Maybe b) -> (a,b) -> Maybe (a,b)
anyJust2 f g (a,b) =
case (f a, g b) of
(Nothing, Nothing) -> Nothing
(x,y) -> Just (fromMaybe a x, fromMaybe b y)
(Just x , Nothing) -> Just (x, b)
(Nothing, Just y ) -> Just (a, y)
(Just x , Just y ) -> Just (x, y)

0 comments on commit c0f6d1c

Please sign in to comment.