{-# LANGUAGE DeriveAnyClass #-}

-- | Utilities for gathering and caching sets of free variables.
module Blanks.Tracked
  ( Tracked (..)
  , mkTrackedFree
  , mkTrackedBound
  , shiftTracked
  , WithTracked (..)
  , forgetTrackedScope
  , trackScope
  , trackScopeSimple
  ) where

import Blanks.Conversion (scopeAnno)
import Blanks.LocScope (LocScope, pattern LocScopeBinder, pattern LocScopeBound, pattern LocScopeEmbed,
                        pattern LocScopeFree, locScopeHoistAnno)
import Blanks.Scope (Scope)
import Control.DeepSeq (NFData)
import Data.Set (Set)
import qualified Data.Set as Set
import GHC.Generics (Generic)

data Tracked a = Tracked
  { Tracked a -> Set a
trackedFree :: !(Set a)
  , Tracked a -> Set Int
trackedBound :: !(Set Int)
  } deriving stock (Tracked a -> Tracked a -> Bool
(Tracked a -> Tracked a -> Bool)
-> (Tracked a -> Tracked a -> Bool) -> Eq (Tracked a)
forall a. Eq a => Tracked a -> Tracked a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Tracked a -> Tracked a -> Bool
$c/= :: forall a. Eq a => Tracked a -> Tracked a -> Bool
== :: Tracked a -> Tracked a -> Bool
$c== :: forall a. Eq a => Tracked a -> Tracked a -> Bool
Eq, Int -> Tracked a -> ShowS
[Tracked a] -> ShowS
Tracked a -> String
(Int -> Tracked a -> ShowS)
-> (Tracked a -> String)
-> ([Tracked a] -> ShowS)
-> Show (Tracked a)
forall a. Show a => Int -> Tracked a -> ShowS
forall a. Show a => [Tracked a] -> ShowS
forall a. Show a => Tracked a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Tracked a] -> ShowS
$cshowList :: forall a. Show a => [Tracked a] -> ShowS
show :: Tracked a -> String
$cshow :: forall a. Show a => Tracked a -> String
showsPrec :: Int -> Tracked a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Tracked a -> ShowS
Show, (forall x. Tracked a -> Rep (Tracked a) x)
-> (forall x. Rep (Tracked a) x -> Tracked a)
-> Generic (Tracked a)
forall x. Rep (Tracked a) x -> Tracked a
forall x. Tracked a -> Rep (Tracked a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Tracked a) x -> Tracked a
forall a x. Tracked a -> Rep (Tracked a) x
$cto :: forall a x. Rep (Tracked a) x -> Tracked a
$cfrom :: forall a x. Tracked a -> Rep (Tracked a) x
Generic)
    deriving anyclass (Tracked a -> ()
(Tracked a -> ()) -> NFData (Tracked a)
forall a. NFData a => Tracked a -> ()
forall a. (a -> ()) -> NFData a
rnf :: Tracked a -> ()
$crnf :: forall a. NFData a => Tracked a -> ()
NFData)

mkTrackedFree :: a -> Tracked a
mkTrackedFree :: a -> Tracked a
mkTrackedFree a :: a
a = Set a -> Set Int -> Tracked a
forall a. Set a -> Set Int -> Tracked a
Tracked (a -> Set a
forall a. a -> Set a
Set.singleton a
a) Set Int
forall a. Set a
Set.empty

mkTrackedBound :: Int -> Tracked a
mkTrackedBound :: Int -> Tracked a
mkTrackedBound b :: Int
b = Set a -> Set Int -> Tracked a
forall a. Set a -> Set Int -> Tracked a
Tracked Set a
forall a. Set a
Set.empty (Int -> Set Int
forall a. a -> Set a
Set.singleton Int
b)

shiftTracked :: Int -> Tracked a -> Tracked a
shiftTracked :: Int -> Tracked a -> Tracked a
shiftTracked i :: Int
i t :: Tracked a
t@(Tracked f :: Set a
f b :: Set Int
b) =
  if Set Int -> Bool
forall a. Set a -> Bool
Set.null Set Int
b
    then Tracked a
t
    else
      let !b' :: Set Int
b' = if Set Int -> Int
forall a. Set a -> a
Set.findMax Set Int
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
i then Set Int
forall a. Set a
Set.empty else (Int -> Bool) -> Set Int -> Set Int
forall a. (a -> Bool) -> Set a -> Set a
Set.dropWhileAntitone (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 0) ((Int -> Int) -> Set Int -> Set Int
forall a b. (a -> b) -> Set a -> Set b
Set.mapMonotonic (\x :: Int
x -> Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) Set Int
b)
      in Set a -> Set Int -> Tracked a
forall a. Set a -> Set Int -> Tracked a
Tracked Set a
f Set Int
b'

instance Ord a => Semigroup (Tracked a) where
  Tracked f1 :: Set a
f1 b1 :: Set Int
b1 <> :: Tracked a -> Tracked a -> Tracked a
<> Tracked f2 :: Set a
f2 b2 :: Set Int
b2 = Set a -> Set Int -> Tracked a
forall a. Set a -> Set Int -> Tracked a
Tracked (Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.union Set a
f1 Set a
f2) (Set Int -> Set Int -> Set Int
forall a. Ord a => Set a -> Set a -> Set a
Set.union Set Int
b1 Set Int
b2)

instance Ord a => Monoid (Tracked a) where
  mempty :: Tracked a
mempty = Set a -> Set Int -> Tracked a
forall a. Set a -> Set Int -> Tracked a
Tracked Set a
forall a. Set a
Set.empty Set Int
forall a. Set a
Set.empty
  mappend :: Tracked a -> Tracked a -> Tracked a
mappend = Tracked a -> Tracked a -> Tracked a
forall a. Semigroup a => a -> a -> a
(<>)

data WithTracked a l = WithTracked
  { WithTracked a l -> Tracked a
withTrackedState :: !(Tracked a)
  , WithTracked a l -> l
withTrackedEnv :: !l
  } deriving stock (WithTracked a l -> WithTracked a l -> Bool
(WithTracked a l -> WithTracked a l -> Bool)
-> (WithTracked a l -> WithTracked a l -> Bool)
-> Eq (WithTracked a l)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a l.
(Eq a, Eq l) =>
WithTracked a l -> WithTracked a l -> Bool
/= :: WithTracked a l -> WithTracked a l -> Bool
$c/= :: forall a l.
(Eq a, Eq l) =>
WithTracked a l -> WithTracked a l -> Bool
== :: WithTracked a l -> WithTracked a l -> Bool
$c== :: forall a l.
(Eq a, Eq l) =>
WithTracked a l -> WithTracked a l -> Bool
Eq, Int -> WithTracked a l -> ShowS
[WithTracked a l] -> ShowS
WithTracked a l -> String
(Int -> WithTracked a l -> ShowS)
-> (WithTracked a l -> String)
-> ([WithTracked a l] -> ShowS)
-> Show (WithTracked a l)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a l. (Show a, Show l) => Int -> WithTracked a l -> ShowS
forall a l. (Show a, Show l) => [WithTracked a l] -> ShowS
forall a l. (Show a, Show l) => WithTracked a l -> String
showList :: [WithTracked a l] -> ShowS
$cshowList :: forall a l. (Show a, Show l) => [WithTracked a l] -> ShowS
show :: WithTracked a l -> String
$cshow :: forall a l. (Show a, Show l) => WithTracked a l -> String
showsPrec :: Int -> WithTracked a l -> ShowS
$cshowsPrec :: forall a l. (Show a, Show l) => Int -> WithTracked a l -> ShowS
Show, (forall x. WithTracked a l -> Rep (WithTracked a l) x)
-> (forall x. Rep (WithTracked a l) x -> WithTracked a l)
-> Generic (WithTracked a l)
forall x. Rep (WithTracked a l) x -> WithTracked a l
forall x. WithTracked a l -> Rep (WithTracked a l) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a l x. Rep (WithTracked a l) x -> WithTracked a l
forall a l x. WithTracked a l -> Rep (WithTracked a l) x
$cto :: forall a l x. Rep (WithTracked a l) x -> WithTracked a l
$cfrom :: forall a l x. WithTracked a l -> Rep (WithTracked a l) x
Generic, a -> WithTracked a b -> WithTracked a a
(a -> b) -> WithTracked a a -> WithTracked a b
(forall a b. (a -> b) -> WithTracked a a -> WithTracked a b)
-> (forall a b. a -> WithTracked a b -> WithTracked a a)
-> Functor (WithTracked a)
forall a b. a -> WithTracked a b -> WithTracked a a
forall a b. (a -> b) -> WithTracked a a -> WithTracked a b
forall a a b. a -> WithTracked a b -> WithTracked a a
forall a a b. (a -> b) -> WithTracked a a -> WithTracked a b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> WithTracked a b -> WithTracked a a
$c<$ :: forall a a b. a -> WithTracked a b -> WithTracked a a
fmap :: (a -> b) -> WithTracked a a -> WithTracked a b
$cfmap :: forall a a b. (a -> b) -> WithTracked a a -> WithTracked a b
Functor, WithTracked a a -> Bool
(a -> m) -> WithTracked a a -> m
(a -> b -> b) -> b -> WithTracked a a -> b
(forall m. Monoid m => WithTracked a m -> m)
-> (forall m a. Monoid m => (a -> m) -> WithTracked a a -> m)
-> (forall m a. Monoid m => (a -> m) -> WithTracked a a -> m)
-> (forall a b. (a -> b -> b) -> b -> WithTracked a a -> b)
-> (forall a b. (a -> b -> b) -> b -> WithTracked a a -> b)
-> (forall b a. (b -> a -> b) -> b -> WithTracked a a -> b)
-> (forall b a. (b -> a -> b) -> b -> WithTracked a a -> b)
-> (forall a. (a -> a -> a) -> WithTracked a a -> a)
-> (forall a. (a -> a -> a) -> WithTracked a a -> a)
-> (forall a. WithTracked a a -> [a])
-> (forall a. WithTracked a a -> Bool)
-> (forall a. WithTracked a a -> Int)
-> (forall a. Eq a => a -> WithTracked a a -> Bool)
-> (forall a. Ord a => WithTracked a a -> a)
-> (forall a. Ord a => WithTracked a a -> a)
-> (forall a. Num a => WithTracked a a -> a)
-> (forall a. Num a => WithTracked a a -> a)
-> Foldable (WithTracked a)
forall a. Eq a => a -> WithTracked a a -> Bool
forall a. Num a => WithTracked a a -> a
forall a. Ord a => WithTracked a a -> a
forall m. Monoid m => WithTracked a m -> m
forall a. WithTracked a a -> Bool
forall a. WithTracked a a -> Int
forall a. WithTracked a a -> [a]
forall a. (a -> a -> a) -> WithTracked a a -> a
forall a a. Eq a => a -> WithTracked a a -> Bool
forall a a. Num a => WithTracked a a -> a
forall a a. Ord a => WithTracked a a -> a
forall m a. Monoid m => (a -> m) -> WithTracked a a -> m
forall a m. Monoid m => WithTracked a m -> m
forall a a. WithTracked a a -> Bool
forall a a. WithTracked a a -> Int
forall a a. WithTracked a a -> [a]
forall b a. (b -> a -> b) -> b -> WithTracked a a -> b
forall a b. (a -> b -> b) -> b -> WithTracked a a -> b
forall a a. (a -> a -> a) -> WithTracked a a -> a
forall a m a. Monoid m => (a -> m) -> WithTracked a a -> m
forall a b a. (b -> a -> b) -> b -> WithTracked a a -> b
forall a a b. (a -> b -> b) -> b -> WithTracked a a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: WithTracked a a -> a
$cproduct :: forall a a. Num a => WithTracked a a -> a
sum :: WithTracked a a -> a
$csum :: forall a a. Num a => WithTracked a a -> a
minimum :: WithTracked a a -> a
$cminimum :: forall a a. Ord a => WithTracked a a -> a
maximum :: WithTracked a a -> a
$cmaximum :: forall a a. Ord a => WithTracked a a -> a
elem :: a -> WithTracked a a -> Bool
$celem :: forall a a. Eq a => a -> WithTracked a a -> Bool
length :: WithTracked a a -> Int
$clength :: forall a a. WithTracked a a -> Int
null :: WithTracked a a -> Bool
$cnull :: forall a a. WithTracked a a -> Bool
toList :: WithTracked a a -> [a]
$ctoList :: forall a a. WithTracked a a -> [a]
foldl1 :: (a -> a -> a) -> WithTracked a a -> a
$cfoldl1 :: forall a a. (a -> a -> a) -> WithTracked a a -> a
foldr1 :: (a -> a -> a) -> WithTracked a a -> a
$cfoldr1 :: forall a a. (a -> a -> a) -> WithTracked a a -> a
foldl' :: (b -> a -> b) -> b -> WithTracked a a -> b
$cfoldl' :: forall a b a. (b -> a -> b) -> b -> WithTracked a a -> b
foldl :: (b -> a -> b) -> b -> WithTracked a a -> b
$cfoldl :: forall a b a. (b -> a -> b) -> b -> WithTracked a a -> b
foldr' :: (a -> b -> b) -> b -> WithTracked a a -> b
$cfoldr' :: forall a a b. (a -> b -> b) -> b -> WithTracked a a -> b
foldr :: (a -> b -> b) -> b -> WithTracked a a -> b
$cfoldr :: forall a a b. (a -> b -> b) -> b -> WithTracked a a -> b
foldMap' :: (a -> m) -> WithTracked a a -> m
$cfoldMap' :: forall a m a. Monoid m => (a -> m) -> WithTracked a a -> m
foldMap :: (a -> m) -> WithTracked a a -> m
$cfoldMap :: forall a m a. Monoid m => (a -> m) -> WithTracked a a -> m
fold :: WithTracked a m -> m
$cfold :: forall a m. Monoid m => WithTracked a m -> m
Foldable, Functor (WithTracked a)
Foldable (WithTracked a)
(Functor (WithTracked a), Foldable (WithTracked a)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> WithTracked a a -> f (WithTracked a b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    WithTracked a (f a) -> f (WithTracked a a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> WithTracked a a -> m (WithTracked a b))
-> (forall (m :: * -> *) a.
    Monad m =>
    WithTracked a (m a) -> m (WithTracked a a))
-> Traversable (WithTracked a)
(a -> f b) -> WithTracked a a -> f (WithTracked a b)
forall a. Functor (WithTracked a)
forall a. Foldable (WithTracked a)
forall a (m :: * -> *) a.
Monad m =>
WithTracked a (m a) -> m (WithTracked a a)
forall a (f :: * -> *) a.
Applicative f =>
WithTracked a (f a) -> f (WithTracked a a)
forall a (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithTracked a a -> m (WithTracked a b)
forall a (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WithTracked a a -> f (WithTracked a b)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
WithTracked a (m a) -> m (WithTracked a a)
forall (f :: * -> *) a.
Applicative f =>
WithTracked a (f a) -> f (WithTracked a a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithTracked a a -> m (WithTracked a b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WithTracked a a -> f (WithTracked a b)
sequence :: WithTracked a (m a) -> m (WithTracked a a)
$csequence :: forall a (m :: * -> *) a.
Monad m =>
WithTracked a (m a) -> m (WithTracked a a)
mapM :: (a -> m b) -> WithTracked a a -> m (WithTracked a b)
$cmapM :: forall a (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithTracked a a -> m (WithTracked a b)
sequenceA :: WithTracked a (f a) -> f (WithTracked a a)
$csequenceA :: forall a (f :: * -> *) a.
Applicative f =>
WithTracked a (f a) -> f (WithTracked a a)
traverse :: (a -> f b) -> WithTracked a a -> f (WithTracked a b)
$ctraverse :: forall a (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WithTracked a a -> f (WithTracked a b)
$cp2Traversable :: forall a. Foldable (WithTracked a)
$cp1Traversable :: forall a. Functor (WithTracked a)
Traversable)
    deriving anyclass (WithTracked a l -> ()
(WithTracked a l -> ()) -> NFData (WithTracked a l)
forall a. (a -> ()) -> NFData a
forall a l. (NFData a, NFData l) => WithTracked a l -> ()
rnf :: WithTracked a l -> ()
$crnf :: forall a l. (NFData a, NFData l) => WithTracked a l -> ()
NFData)

forgetTrackedScope :: Functor f => LocScope (WithTracked a l) n f z -> LocScope l n f z
forgetTrackedScope :: LocScope (WithTracked a l) n f z -> LocScope l n f z
forgetTrackedScope = (WithTracked a l -> l)
-> LocScope (WithTracked a l) n f z -> LocScope l n f z
forall (f :: * -> *) l x n a.
Functor f =>
(l -> x) -> LocScope l n f a -> LocScope x n f a
locScopeHoistAnno WithTracked a l -> l
forall a l. WithTracked a l -> l
withTrackedEnv

trackScopeInner :: (Traversable f, Ord a) => LocScope l n f a -> (Tracked a, LocScope (WithTracked a l) n f a)
trackScopeInner :: LocScope l n f a -> (Tracked a, LocScope (WithTracked a l) n f a)
trackScopeInner s :: LocScope l n f a
s =
  case LocScope l n f a
s of
    LocScopeBound l :: l
l b :: Int
b ->
      let !t :: Tracked a
t = Set a -> Set Int -> Tracked a
forall a. Set a -> Set Int -> Tracked a
Tracked Set a
forall a. Set a
Set.empty (Int -> Set Int
forall a. a -> Set a
Set.singleton Int
b)
          !m :: WithTracked a l
m = Tracked a -> l -> WithTracked a l
forall a l. Tracked a -> l -> WithTracked a l
WithTracked Tracked a
t l
l
      in (Tracked a
t, WithTracked a l -> Int -> LocScope (WithTracked a l) n f a
forall l n (f :: * -> *) a. l -> Int -> LocScope l n f a
LocScopeBound WithTracked a l
m Int
b)
    LocScopeFree l :: l
l a :: a
a ->
      let !t :: Tracked a
t = Set a -> Set Int -> Tracked a
forall a. Set a -> Set Int -> Tracked a
Tracked (a -> Set a
forall a. a -> Set a
Set.singleton a
a) Set Int
forall a. Set a
Set.empty
          !m :: WithTracked a l
m = Tracked a -> l -> WithTracked a l
forall a l. Tracked a -> l -> WithTracked a l
WithTracked Tracked a
t l
l
      in (Tracked a
t, WithTracked a l -> a -> LocScope (WithTracked a l) n f a
forall l a n (f :: * -> *). l -> a -> LocScope l n f a
LocScopeFree WithTracked a l
m a
a)
    LocScopeBinder l :: l
l n :: Int
n i :: n
i e :: LocScope l n f a
e ->
      let !(t0 :: Tracked a
t0, y :: LocScope (WithTracked a l) n f a
y) = LocScope l n f a -> (Tracked a, LocScope (WithTracked a l) n f a)
forall (f :: * -> *) a l n.
(Traversable f, Ord a) =>
LocScope l n f a -> (Tracked a, LocScope (WithTracked a l) n f a)
trackScopeInner LocScope l n f a
e
          !t :: Tracked a
t = Int -> Tracked a -> Tracked a
forall a. Int -> Tracked a -> Tracked a
shiftTracked Int
n Tracked a
t0
          !m :: WithTracked a l
m = Tracked a -> l -> WithTracked a l
forall a l. Tracked a -> l -> WithTracked a l
WithTracked Tracked a
t l
l
      in (Tracked a
t, WithTracked a l
-> Int
-> n
-> LocScope (WithTracked a l) n f a
-> LocScope (WithTracked a l) n f a
forall l n (f :: * -> *) a.
l -> Int -> n -> LocScope l n f a -> LocScope l n f a
LocScopeBinder WithTracked a l
m Int
n n
i LocScope (WithTracked a l) n f a
y)
    LocScopeEmbed l :: l
l fe :: f (LocScope l n f a)
fe ->
      let (!Tracked a
t, !f (LocScope (WithTracked a l) n f a)
fy) = (LocScope l n f a -> (Tracked a, LocScope (WithTracked a l) n f a))
-> f (LocScope l n f a)
-> (Tracked a, f (LocScope (WithTracked a l) n f a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse LocScope l n f a -> (Tracked a, LocScope (WithTracked a l) n f a)
forall (f :: * -> *) a l n.
(Traversable f, Ord a) =>
LocScope l n f a -> (Tracked a, LocScope (WithTracked a l) n f a)
trackScopeInner f (LocScope l n f a)
fe
          !m :: WithTracked a l
m = Tracked a -> l -> WithTracked a l
forall a l. Tracked a -> l -> WithTracked a l
WithTracked Tracked a
t l
l
      in (Tracked a
t, WithTracked a l
-> f (LocScope (WithTracked a l) n f a)
-> LocScope (WithTracked a l) n f a
forall l (f :: * -> *) n a.
l -> f (LocScope l n f a) -> LocScope l n f a
LocScopeEmbed WithTracked a l
m f (LocScope (WithTracked a l) n f a)
fy)

trackScope :: (Traversable f, Ord a) => LocScope l n f a -> LocScope (WithTracked a l) n f a
trackScope :: LocScope l n f a -> LocScope (WithTracked a l) n f a
trackScope = (Tracked a, LocScope (WithTracked a l) n f a)
-> LocScope (WithTracked a l) n f a
forall a b. (a, b) -> b
snd ((Tracked a, LocScope (WithTracked a l) n f a)
 -> LocScope (WithTracked a l) n f a)
-> (LocScope l n f a
    -> (Tracked a, LocScope (WithTracked a l) n f a))
-> LocScope l n f a
-> LocScope (WithTracked a l) n f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocScope l n f a -> (Tracked a, LocScope (WithTracked a l) n f a)
forall (f :: * -> *) a l n.
(Traversable f, Ord a) =>
LocScope l n f a -> (Tracked a, LocScope (WithTracked a l) n f a)
trackScopeInner

trackScopeSimple :: (Traversable f, Ord a) => Scope n f a -> LocScope (Tracked a) n f a
trackScopeSimple :: Scope n f a -> LocScope (Tracked a) n f a
trackScopeSimple = (WithTracked a () -> Tracked a)
-> LocScope (WithTracked a ()) n f a -> LocScope (Tracked a) n f a
forall (f :: * -> *) l x n a.
Functor f =>
(l -> x) -> LocScope l n f a -> LocScope x n f a
locScopeHoistAnno WithTracked a () -> Tracked a
forall a l. WithTracked a l -> Tracked a
withTrackedState (LocScope (WithTracked a ()) n f a -> LocScope (Tracked a) n f a)
-> (Scope n f a -> LocScope (WithTracked a ()) n f a)
-> Scope n f a
-> LocScope (Tracked a) n f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocScope () n f a -> LocScope (WithTracked a ()) n f a
forall (f :: * -> *) a l n.
(Traversable f, Ord a) =>
LocScope l n f a -> LocScope (WithTracked a l) n f a
trackScope (LocScope () n f a -> LocScope (WithTracked a ()) n f a)
-> (Scope n f a -> LocScope () n f a)
-> Scope n f a
-> LocScope (WithTracked a ()) n f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Scope n f a -> LocScope () n f a
forall (f :: * -> *) l n a.
Functor f =>
l -> Scope n f a -> LocScope l n f a
scopeAnno ()