{-# LANGUAGE RecordWildCards #-}
module GhcDump.Reconstruct (reconModule) where

import Data.Foldable
import Data.Bifunctor
import Prelude hiding (readFile)

import Data.Hashable
import qualified Data.HashMap.Lazy as HM

import GhcDump.Ast

newtype BinderMap = BinderMap (HM.HashMap BinderId Binder)

instance Hashable BinderId where
    hashWithSalt :: Int -> BinderId -> Int
hashWithSalt Int
salt (BinderId (Unique Char
c Int
i)) = Int
salt Int -> Char -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` Char
c Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` Int
i

emptyBinderMap :: BinderMap
emptyBinderMap :: BinderMap
emptyBinderMap = HashMap BinderId Binder -> BinderMap
BinderMap HashMap BinderId Binder
forall a. Monoid a => a
mempty

insertBinder :: Binder -> BinderMap -> BinderMap
insertBinder :: Binder -> BinderMap -> BinderMap
insertBinder (Bndr Binder' Binder Binder
b) (BinderMap HashMap BinderId Binder
m) = HashMap BinderId Binder -> BinderMap
BinderMap (HashMap BinderId Binder -> BinderMap)
-> HashMap BinderId Binder -> BinderMap
forall a b. (a -> b) -> a -> b
$ BinderId
-> Binder -> HashMap BinderId Binder -> HashMap BinderId Binder
forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
HM.insert (Binder' Binder Binder -> BinderId
forall bndr var. Binder' bndr var -> BinderId
binderId Binder' Binder Binder
b) (Binder' Binder Binder -> Binder
Bndr Binder' Binder Binder
b) HashMap BinderId Binder
m

insertBinders :: [Binder] -> BinderMap -> BinderMap
insertBinders :: [Binder] -> BinderMap -> BinderMap
insertBinders [Binder]
bs BinderMap
bm = (BinderMap -> Binder -> BinderMap)
-> BinderMap -> [Binder] -> BinderMap
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' ((Binder -> BinderMap -> BinderMap)
-> BinderMap -> Binder -> BinderMap
forall a b c. (a -> b -> c) -> b -> a -> c
flip Binder -> BinderMap -> BinderMap
insertBinder) BinderMap
bm [Binder]
bs

getBinder :: BinderMap -> BinderId -> Binder
getBinder :: BinderMap -> BinderId -> Binder
getBinder (BinderMap HashMap BinderId Binder
m) BinderId
bid
  | Just Binder
b <- BinderId -> HashMap BinderId Binder -> Maybe Binder
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HM.lookup BinderId
bid HashMap BinderId Binder
m = Binder
b
  | Bool
otherwise                 = [Char] -> Binder
forall a. HasCallStack => [Char] -> a
error ([Char] -> Binder) -> [Char] -> Binder
forall a b. (a -> b) -> a -> b
$ [Char]
"unknown binder "[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ BinderId -> [Char]
forall a. Show a => a -> [Char]
show BinderId
bid [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
":\nin scope:\n"
                                        [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [[Char]] -> [Char]
unlines (((BinderId, Binder) -> [Char]) -> [(BinderId, Binder)] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
map (\(BinderId
bid',Binder
b) -> BinderId -> [Char]
forall a. Show a => a -> [Char]
show BinderId
bid' [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"\t" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Binder -> [Char]
forall a. Show a => a -> [Char]
show Binder
b) (HashMap BinderId Binder -> [(BinderId, Binder)]
forall k v. HashMap k v -> [(k, v)]
HM.toList HashMap BinderId Binder
m))

-- "recon" == "reconstruct"

reconModule :: SModule -> Module
reconModule :: SModule -> Module
reconModule SModule
m = ModuleName -> Text -> [TopBinding' Binder Binder] -> Module
forall bndr var.
ModuleName -> Text -> [TopBinding' bndr var] -> Module' bndr var
Module (SModule -> ModuleName
forall bndr var. Module' bndr var -> ModuleName
moduleName SModule
m) (SModule -> Text
forall bndr var. Module' bndr var -> Text
modulePhase SModule
m) [TopBinding' Binder Binder]
binds
  where
    binds :: [TopBinding' Binder Binder]
binds = (STopBinding -> TopBinding' Binder Binder)
-> [STopBinding] -> [TopBinding' Binder Binder]
forall a b. (a -> b) -> [a] -> [b]
map STopBinding -> TopBinding' Binder Binder
reconTopBinding ([STopBinding] -> [TopBinding' Binder Binder])
-> [STopBinding] -> [TopBinding' Binder Binder]
forall a b. (a -> b) -> a -> b
$ SModule -> [STopBinding]
forall bndr var. Module' bndr var -> [TopBinding' bndr var]
moduleTopBindings SModule
m
    bm :: BinderMap
bm = [Binder] -> BinderMap -> BinderMap
insertBinders (((Binder, CoreStats, Expr' Binder Binder) -> Binder)
-> [(Binder, CoreStats, Expr' Binder Binder)] -> [Binder]
forall a b. (a -> b) -> [a] -> [b]
map (\(Binder
a,CoreStats
_,Expr' Binder Binder
_) -> Binder
a) ([(Binder, CoreStats, Expr' Binder Binder)] -> [Binder])
-> [(Binder, CoreStats, Expr' Binder Binder)] -> [Binder]
forall a b. (a -> b) -> a -> b
$ (TopBinding' Binder Binder
 -> [(Binder, CoreStats, Expr' Binder Binder)])
-> [TopBinding' Binder Binder]
-> [(Binder, CoreStats, Expr' Binder Binder)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap TopBinding' Binder Binder
-> [(Binder, CoreStats, Expr' Binder Binder)]
forall bndr var.
TopBinding' bndr var -> [(bndr, CoreStats, Expr' bndr var)]
topBindings [TopBinding' Binder Binder]
binds) BinderMap
emptyBinderMap

    reconTopBinding :: STopBinding -> TopBinding
    reconTopBinding :: STopBinding -> TopBinding' Binder Binder
reconTopBinding (NonRecTopBinding SBinder
b CoreStats
stats Expr' SBinder BinderId
rhs) = Binder
-> CoreStats -> Expr' Binder Binder -> TopBinding' Binder Binder
forall bndr var.
bndr -> CoreStats -> Expr' bndr var -> TopBinding' bndr var
NonRecTopBinding Binder
b' CoreStats
stats (BinderMap -> Expr' SBinder BinderId -> Expr' Binder Binder
reconExpr BinderMap
bm Expr' SBinder BinderId
rhs)
      where b' :: Binder
b' = BinderMap -> SBinder -> Binder
reconBinder BinderMap
bm SBinder
b
    reconTopBinding (RecTopBinding [(SBinder, CoreStats, Expr' SBinder BinderId)]
bs) = [(Binder, CoreStats, Expr' Binder Binder)]
-> TopBinding' Binder Binder
forall bndr var.
[(bndr, CoreStats, Expr' bndr var)] -> TopBinding' bndr var
RecTopBinding [(Binder, CoreStats, Expr' Binder Binder)]
bs'
      where bs' :: [(Binder, CoreStats, Expr' Binder Binder)]
bs' = ((SBinder, CoreStats, Expr' SBinder BinderId)
 -> (Binder, CoreStats, Expr' Binder Binder))
-> [(SBinder, CoreStats, Expr' SBinder BinderId)]
-> [(Binder, CoreStats, Expr' Binder Binder)]
forall a b. (a -> b) -> [a] -> [b]
map (\(SBinder
a,CoreStats
stats,Expr' SBinder BinderId
rhs) -> (BinderMap -> SBinder -> Binder
reconBinder BinderMap
bm SBinder
a, CoreStats
stats, BinderMap -> Expr' SBinder BinderId -> Expr' Binder Binder
reconExpr BinderMap
bm Expr' SBinder BinderId
rhs)) [(SBinder, CoreStats, Expr' SBinder BinderId)]
bs

reconExpr :: BinderMap -> SExpr -> Expr
reconExpr :: BinderMap -> Expr' SBinder BinderId -> Expr' Binder Binder
reconExpr BinderMap
bm (EVar BinderId
var)       = Binder -> Expr' Binder Binder
forall bndr var. var -> Expr' bndr var
EVar (Binder -> Expr' Binder Binder) -> Binder -> Expr' Binder Binder
forall a b. (a -> b) -> a -> b
$ BinderMap -> BinderId -> Binder
getBinder BinderMap
bm BinderId
var
reconExpr BinderMap
_  (EVarGlobal ExternalName
n)   = ExternalName -> Expr' Binder Binder
forall bndr var. ExternalName -> Expr' bndr var
EVarGlobal ExternalName
n
reconExpr BinderMap
_  (ELit Lit
l)         = Lit -> Expr' Binder Binder
forall bndr var. Lit -> Expr' bndr var
ELit Lit
l
reconExpr BinderMap
bm (EApp Expr' SBinder BinderId
x Expr' SBinder BinderId
y)       = Expr' Binder Binder -> Expr' Binder Binder -> Expr' Binder Binder
forall bndr var. Expr' bndr var -> Expr' bndr var -> Expr' bndr var
EApp (BinderMap -> Expr' SBinder BinderId -> Expr' Binder Binder
reconExpr BinderMap
bm Expr' SBinder BinderId
x) (BinderMap -> Expr' SBinder BinderId -> Expr' Binder Binder
reconExpr BinderMap
bm Expr' SBinder BinderId
y)
reconExpr BinderMap
bm (ETyLam SBinder
b Expr' SBinder BinderId
x)     = let b' :: Binder
b' = BinderMap -> SBinder -> Binder
reconBinder BinderMap
bm SBinder
b
                                    bm' :: BinderMap
bm' = Binder -> BinderMap -> BinderMap
insertBinder Binder
b' BinderMap
bm
                                in Binder -> Expr' Binder Binder -> Expr' Binder Binder
forall bndr var. bndr -> Expr' bndr var -> Expr' bndr var
ETyLam Binder
b' (BinderMap -> Expr' SBinder BinderId -> Expr' Binder Binder
reconExpr BinderMap
bm' Expr' SBinder BinderId
x)
reconExpr BinderMap
bm (ELam SBinder
b Expr' SBinder BinderId
x)       = let b' :: Binder
b' = BinderMap -> SBinder -> Binder
reconBinder BinderMap
bm SBinder
b
                                    bm' :: BinderMap
bm' = Binder -> BinderMap -> BinderMap
insertBinder Binder
b' BinderMap
bm
                                in Binder -> Expr' Binder Binder -> Expr' Binder Binder
forall bndr var. bndr -> Expr' bndr var -> Expr' bndr var
ELam Binder
b' (BinderMap -> Expr' SBinder BinderId -> Expr' Binder Binder
reconExpr BinderMap
bm' Expr' SBinder BinderId
x)
reconExpr BinderMap
bm (ELet [(SBinder, Expr' SBinder BinderId)]
bs Expr' SBinder BinderId
x)      = let bs' :: [(Binder, Expr' Binder Binder)]
bs' = ((SBinder, Expr' SBinder BinderId)
 -> (Binder, Expr' Binder Binder))
-> [(SBinder, Expr' SBinder BinderId)]
-> [(Binder, Expr' Binder Binder)]
forall a b. (a -> b) -> [a] -> [b]
map ((SBinder -> Binder)
-> (Expr' SBinder BinderId -> Expr' Binder Binder)
-> (SBinder, Expr' SBinder BinderId)
-> (Binder, Expr' Binder Binder)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap (BinderMap -> SBinder -> Binder
reconBinder BinderMap
bm) (BinderMap -> Expr' SBinder BinderId -> Expr' Binder Binder
reconExpr BinderMap
bm')) [(SBinder, Expr' SBinder BinderId)]
bs
                                    bm' :: BinderMap
bm' = [Binder] -> BinderMap -> BinderMap
insertBinders (((Binder, Expr' Binder Binder) -> Binder)
-> [(Binder, Expr' Binder Binder)] -> [Binder]
forall a b. (a -> b) -> [a] -> [b]
map (Binder, Expr' Binder Binder) -> Binder
forall a b. (a, b) -> a
fst [(Binder, Expr' Binder Binder)]
bs') BinderMap
bm
                                in [(Binder, Expr' Binder Binder)]
-> Expr' Binder Binder -> Expr' Binder Binder
forall bndr var.
[(bndr, Expr' bndr var)] -> Expr' bndr var -> Expr' bndr var
ELet [(Binder, Expr' Binder Binder)]
bs' (BinderMap -> Expr' SBinder BinderId -> Expr' Binder Binder
reconExpr BinderMap
bm' Expr' SBinder BinderId
x)
reconExpr BinderMap
bm (ECase Expr' SBinder BinderId
x SBinder
b [Alt' SBinder BinderId]
alts) = let b' :: Binder
b' = BinderMap -> SBinder -> Binder
reconBinder BinderMap
bm SBinder
b
                                    bm' :: BinderMap
bm' = Binder -> BinderMap -> BinderMap
insertBinder Binder
b' BinderMap
bm
                                in Expr' Binder Binder
-> Binder -> [Alt' Binder Binder] -> Expr' Binder Binder
forall bndr var.
Expr' bndr var -> bndr -> [Alt' bndr var] -> Expr' bndr var
ECase (BinderMap -> Expr' SBinder BinderId -> Expr' Binder Binder
reconExpr BinderMap
bm Expr' SBinder BinderId
x) Binder
b' ((Alt' SBinder BinderId -> Alt' Binder Binder)
-> [Alt' SBinder BinderId] -> [Alt' Binder Binder]
forall a b. (a -> b) -> [a] -> [b]
map (BinderMap -> Alt' SBinder BinderId -> Alt' Binder Binder
reconAlt BinderMap
bm') [Alt' SBinder BinderId]
alts)
reconExpr BinderMap
bm (EType Type' SBinder BinderId
t)        = Type' Binder Binder -> Expr' Binder Binder
forall bndr var. Type' bndr var -> Expr' bndr var
EType (BinderMap -> Type' SBinder BinderId -> Type' Binder Binder
reconType BinderMap
bm Type' SBinder BinderId
t)
reconExpr BinderMap
_  Expr' SBinder BinderId
ECoercion        = Expr' Binder Binder
forall bndr var. Expr' bndr var
ECoercion

reconBinder :: BinderMap -> SBinder -> Binder
reconBinder :: BinderMap -> SBinder -> Binder
reconBinder BinderMap
bm (SBndr b :: Binder' SBinder BinderId
b@Binder{}) =
    Binder' Binder Binder -> Binder
Bndr (Binder' Binder Binder -> Binder)
-> Binder' Binder Binder -> Binder
forall a b. (a -> b) -> a -> b
$ Binder' SBinder BinderId
b { binderType :: Type' Binder Binder
binderType = BinderMap -> Type' SBinder BinderId -> Type' Binder Binder
reconType BinderMap
bm (Type' SBinder BinderId -> Type' Binder Binder)
-> Type' SBinder BinderId -> Type' Binder Binder
forall a b. (a -> b) -> a -> b
$ Binder' SBinder BinderId -> Type' SBinder BinderId
forall bndr var. Binder' bndr var -> Type' bndr var
binderType Binder' SBinder BinderId
b
             , binderIdInfo :: IdInfo Binder Binder
binderIdInfo = BinderMap -> IdInfo SBinder BinderId -> IdInfo Binder Binder
reconIdInfo BinderMap
bm (IdInfo SBinder BinderId -> IdInfo Binder Binder)
-> IdInfo SBinder BinderId -> IdInfo Binder Binder
forall a b. (a -> b) -> a -> b
$ Binder' SBinder BinderId -> IdInfo SBinder BinderId
forall bndr var. Binder' bndr var -> IdInfo bndr var
binderIdInfo Binder' SBinder BinderId
b
             }
reconBinder BinderMap
bm (SBndr b :: Binder' SBinder BinderId
b@TyBinder{}) =
    Binder' Binder Binder -> Binder
Bndr (Binder' Binder Binder -> Binder)
-> Binder' Binder Binder -> Binder
forall a b. (a -> b) -> a -> b
$ Binder' SBinder BinderId
b { binderKind :: Type' Binder Binder
binderKind = BinderMap -> Type' SBinder BinderId -> Type' Binder Binder
reconType BinderMap
bm (Type' SBinder BinderId -> Type' Binder Binder)
-> Type' SBinder BinderId -> Type' Binder Binder
forall a b. (a -> b) -> a -> b
$ Binder' SBinder BinderId -> Type' SBinder BinderId
forall bndr var. Binder' bndr var -> Type' bndr var
binderKind Binder' SBinder BinderId
b }

reconIdInfo :: BinderMap -> IdInfo SBinder BinderId -> IdInfo Binder Binder
reconIdInfo :: BinderMap -> IdInfo SBinder BinderId -> IdInfo Binder Binder
reconIdInfo BinderMap
bm IdInfo SBinder BinderId
i =
    IdInfo SBinder BinderId
i { idiUnfolding :: Unfolding Binder Binder
idiUnfolding = BinderMap -> Unfolding SBinder BinderId -> Unfolding Binder Binder
reconUnfolding BinderMap
bm (Unfolding SBinder BinderId -> Unfolding Binder Binder)
-> Unfolding SBinder BinderId -> Unfolding Binder Binder
forall a b. (a -> b) -> a -> b
$ IdInfo SBinder BinderId -> Unfolding SBinder BinderId
forall bndr var. IdInfo bndr var -> Unfolding bndr var
idiUnfolding IdInfo SBinder BinderId
i }

reconUnfolding :: BinderMap -> Unfolding SBinder BinderId -> Unfolding Binder Binder
reconUnfolding :: BinderMap -> Unfolding SBinder BinderId -> Unfolding Binder Binder
reconUnfolding BinderMap
_  Unfolding SBinder BinderId
NoUnfolding = Unfolding Binder Binder
forall bndr var. Unfolding bndr var
NoUnfolding
reconUnfolding BinderMap
_  Unfolding SBinder BinderId
BootUnfolding = Unfolding Binder Binder
forall bndr var. Unfolding bndr var
BootUnfolding
reconUnfolding BinderMap
_  (OtherCon [AltCon]
alts) = [AltCon] -> Unfolding Binder Binder
forall bndr var. [AltCon] -> Unfolding bndr var
OtherCon [AltCon]
alts
reconUnfolding BinderMap
_  Unfolding SBinder BinderId
DFunUnfolding   = Unfolding Binder Binder
forall bndr var. Unfolding bndr var
DFunUnfolding
reconUnfolding BinderMap
bm CoreUnfolding{Bool
Text
Expr' SBinder BinderId
unfTemplate :: forall bndr var. Unfolding bndr var -> Expr' bndr var
unfIsValue :: forall bndr var. Unfolding bndr var -> Bool
unfIsConLike :: forall bndr var. Unfolding bndr var -> Bool
unfIsWorkFree :: forall bndr var. Unfolding bndr var -> Bool
unfGuidance :: forall bndr var. Unfolding bndr var -> Text
unfGuidance :: Text
unfIsWorkFree :: Bool
unfIsConLike :: Bool
unfIsValue :: Bool
unfTemplate :: Expr' SBinder BinderId
..} = CoreUnfolding :: forall bndr var.
Expr' bndr var
-> Bool -> Bool -> Bool -> Text -> Unfolding bndr var
CoreUnfolding { unfTemplate :: Expr' Binder Binder
unfTemplate = BinderMap -> Expr' SBinder BinderId -> Expr' Binder Binder
reconExpr BinderMap
bm Expr' SBinder BinderId
unfTemplate
                                                    , Bool
Text
unfIsValue :: Bool
unfIsConLike :: Bool
unfIsWorkFree :: Bool
unfGuidance :: Text
unfGuidance :: Text
unfIsWorkFree :: Bool
unfIsConLike :: Bool
unfIsValue :: Bool
.. }

reconAlt :: BinderMap -> SAlt -> Alt
reconAlt :: BinderMap -> Alt' SBinder BinderId -> Alt' Binder Binder
reconAlt BinderMap
bm0 (Alt AltCon
con [SBinder]
bs Expr' SBinder BinderId
rhs) =
    let (BinderMap
bm', [Binder]
bs') = BinderMap -> [Binder] -> [SBinder] -> (BinderMap, [Binder])
doBinders BinderMap
bm0 [] [SBinder]
bs
    in AltCon -> [Binder] -> Expr' Binder Binder -> Alt' Binder Binder
forall bndr var.
AltCon -> [bndr] -> Expr' bndr var -> Alt' bndr var
Alt AltCon
con [Binder]
bs' (BinderMap -> Expr' SBinder BinderId -> Expr' Binder Binder
reconExpr BinderMap
bm' Expr' SBinder BinderId
rhs)
  where
    doBinders :: BinderMap -> [Binder] -> [SBinder] -> (BinderMap, [Binder])
doBinders BinderMap
bm [Binder]
acc []       = (BinderMap
bm, [Binder] -> [Binder]
forall a. [a] -> [a]
reverse [Binder]
acc)
    doBinders BinderMap
bm [Binder]
acc (SBinder
b:[SBinder]
rest) = BinderMap -> [Binder] -> [SBinder] -> (BinderMap, [Binder])
doBinders BinderMap
bm' (Binder
b'Binder -> [Binder] -> [Binder]
forall a. a -> [a] -> [a]
:[Binder]
acc) [SBinder]
rest
      where
        b' :: Binder
b'  = BinderMap -> SBinder -> Binder
reconBinder BinderMap
bm SBinder
b
        bm' :: BinderMap
bm' = Binder -> BinderMap -> BinderMap
insertBinder Binder
b' BinderMap
bm

reconType :: BinderMap -> SType -> Type
reconType :: BinderMap -> Type' SBinder BinderId -> Type' Binder Binder
reconType BinderMap
bm (VarTy BinderId
v) = Binder -> Type' Binder Binder
forall bndr var. var -> Type' bndr var
VarTy (Binder -> Type' Binder Binder) -> Binder -> Type' Binder Binder
forall a b. (a -> b) -> a -> b
$ BinderMap -> BinderId -> Binder
getBinder BinderMap
bm BinderId
v
reconType BinderMap
bm (FunTy Type' SBinder BinderId
x Type' SBinder BinderId
y) = Type' Binder Binder -> Type' Binder Binder -> Type' Binder Binder
forall bndr var. Type' bndr var -> Type' bndr var -> Type' bndr var
FunTy (BinderMap -> Type' SBinder BinderId -> Type' Binder Binder
reconType BinderMap
bm Type' SBinder BinderId
x) (BinderMap -> Type' SBinder BinderId -> Type' Binder Binder
reconType BinderMap
bm Type' SBinder BinderId
y)
reconType BinderMap
bm (TyConApp TyCon
tc [Type' SBinder BinderId]
tys) = TyCon -> [Type' Binder Binder] -> Type' Binder Binder
forall bndr var. TyCon -> [Type' bndr var] -> Type' bndr var
TyConApp TyCon
tc ((Type' SBinder BinderId -> Type' Binder Binder)
-> [Type' SBinder BinderId] -> [Type' Binder Binder]
forall a b. (a -> b) -> [a] -> [b]
map (BinderMap -> Type' SBinder BinderId -> Type' Binder Binder
reconType BinderMap
bm) [Type' SBinder BinderId]
tys)
reconType BinderMap
bm (AppTy Type' SBinder BinderId
x Type' SBinder BinderId
y) = Type' Binder Binder -> Type' Binder Binder -> Type' Binder Binder
forall bndr var. Type' bndr var -> Type' bndr var -> Type' bndr var
AppTy (BinderMap -> Type' SBinder BinderId -> Type' Binder Binder
reconType BinderMap
bm Type' SBinder BinderId
x) (BinderMap -> Type' SBinder BinderId -> Type' Binder Binder
reconType BinderMap
bm Type' SBinder BinderId
y)
reconType BinderMap
bm (ForAllTy SBinder
b Type' SBinder BinderId
x) = let b' :: Binder
b' = BinderMap -> SBinder -> Binder
reconBinder BinderMap
bm SBinder
b
                                  bm' :: BinderMap
bm' = Binder -> BinderMap -> BinderMap
insertBinder Binder
b' BinderMap
bm
                              in Binder -> Type' Binder Binder -> Type' Binder Binder
forall bndr var. bndr -> Type' bndr var -> Type' bndr var
ForAllTy Binder
b' (BinderMap -> Type' SBinder BinderId -> Type' Binder Binder
reconType BinderMap
bm' Type' SBinder BinderId
x)
reconType BinderMap
_  Type' SBinder BinderId
LitTy = Type' Binder Binder
forall bndr var. Type' bndr var
LitTy
reconType BinderMap
_  Type' SBinder BinderId
CoercionTy = Type' Binder Binder
forall bndr var. Type' bndr var
CoercionTy