module Language.Fixpoint.Types.Utils (
kvarDomain
, reftFreeVars
, sortedReftConcKVars
) where
import qualified Data.HashMap.Strict as M
import qualified Data.HashSet as S
import Language.Fixpoint.Misc
import Language.Fixpoint.Types.Names
import Language.Fixpoint.Types.Refinements
import Language.Fixpoint.Types.Environments
import Language.Fixpoint.Types.Constraints
kvarDomain :: SInfo a -> KVar -> [Symbol]
kvarDomain si k = domain (bs si) (getWfC si k)
domain :: BindEnv -> WfC a -> [Symbol]
domain be wfc = fst3 (wrft wfc) : map fst (envCs be $ wenv wfc)
getWfC :: SInfo a -> KVar -> WfC a
getWfC si k = ws si M.! k
reftFreeVars :: Reft -> S.HashSet Symbol
reftFreeVars r@(Reft (v, _)) = S.delete v $ S.fromList $ syms r
sortedReftConcKVars :: Symbol -> SortedReft -> ([Pred], [KVSub], [KVSub])
sortedReftConcKVars x sr = go [] [] [] ves
where
ves = [(v, p `subst1` (v, eVar x)) | Reft (v, p) <- rs ]
rs = reftConjuncts (sr_reft sr)
t = sr_sort sr
go ps ks gs ((v, PKVar k su ):xs) = go ps (KVS v t k su:ks) gs xs
go ps ks gs ((v, PGrad k su _ _):xs) = go ps ks (KVS v t k su:gs) xs
go ps ks gs ((_, p):xs) = go (p:ps) ks gs xs
go ps ks gs [] = (ps, ks, gs)