module Vectorise.Monad.InstEnv
( existsInst
, lookupInst
, lookupFamInst
)
where
import Vectorise.Monad.Global
import Vectorise.Monad.Base
import Vectorise.Env
import DynFlags
import FamInstEnv
import InstEnv
import Class
import Type
import TyCon
import Outputable
import Util
#include "HsVersions.h"
existsInst :: Class -> [Type] -> VM Bool
existsInst cls tys
= do { instEnv <- readGEnv global_inst_env
; return $ either (const False) (const True) (lookupUniqueInstEnv instEnv cls tys)
}
lookupInst :: Class -> [Type] -> VM (DFunId, [Type])
lookupInst cls tys
= do { instEnv <- readGEnv global_inst_env
; case lookupUniqueInstEnv instEnv cls tys of
Right (inst, inst_tys) -> return (instanceDFunId inst, inst_tys)
Left err ->
do dflags <- getDynFlags
cantVectorise dflags "Vectorise.Monad.InstEnv.lookupInst:" err
}
lookupFamInst :: TyCon -> [Type] -> VM FamInstMatch
lookupFamInst tycon tys
= ASSERT( isOpenFamilyTyCon tycon )
do { instEnv <- readGEnv global_fam_inst_env
; case lookupFamInstEnv instEnv tycon tys of
[match] -> return match
_other ->
do dflags <- getDynFlags
cantVectorise dflags "Vectorise.Monad.InstEnv.lookupFamInst: not found: "
(ppr $ mkTyConApp tycon tys)
}