import OccName
import Id
import MkId
-import BasicTypes ( StrictnessMark(..), boolToRecFlag,
- dfunInlinePragma )
+import BasicTypes ( HsBang(..), boolToRecFlag,
+ alwaysInlinePragma, dfunInlinePragma )
import Var ( Var, TyVar, varType )
import Name ( Name, getOccName )
import NameEnv
-- ----------------------------------------------------------------------------
-- Types
+-- | Vectorise a type constructor.
vectTyCon :: TyCon -> VM TyCon
vectTyCon tc
| isFunTyCon tc = builtin closureTyCon
| isBoxedTupleTyCon tc = return tc
| isUnLiftedTyCon tc = return tc
- | otherwise = maybeCantVectoriseM "Tycon not vectorised:" (ppr tc)
- $ lookupTyCon tc
+ | otherwise
+ = maybeCantVectoriseM "Tycon not vectorised: " (ppr tc)
+ $ lookupTyCon tc
+
vectAndLiftType :: Type -> VM (Type, Type)
vectAndLiftType ty | Just ty' <- coreView ty = vectAndLiftType ty'
(tyvars, mono_ty) = splitForAllTys ty
+-- | Vectorise a type.
vectType :: Type -> VM Type
vectType ty | Just ty' <- coreView ty = vectType ty'
vectType (TyVarTy tv) = return $ TyVarTy tv
vectAndBoxType :: Type -> VM Type
vectAndBoxType ty = vectType ty >>= boxType
+-- | Add quantified vars and dictionary parameters to the front of a type.
abstractType :: [TyVar] -> [Type] -> Type -> Type
abstractType tyvars dicts = mkForAllTys tyvars . mkFunTys dicts
case r of
Just tycon' -> return $ mkTyConApp tycon' []
Nothing -> return ty
+
boxType ty = return ty
-- ----------------------------------------------------------------------------
type TyConGroup = ([TyCon], UniqSet TyCon)
+-- | Vectorise a type environment.
+-- The type environment contains all the type things defined in a module.
vectTypeEnv :: TypeEnv -> VM (TypeEnv, [FamInst], [(Var, CoreExpr)])
vectTypeEnv env
= do
cs <- readGEnv $ mk_map . global_tycons
+
+ -- Split the list of TyCons into the ones we have to vectorise vs the
+ -- ones we can pass through unchanged. We also pass through algebraic
+ -- types that use non Haskell98 features, as we don't handle those.
let (conv_tcs, keep_tcs) = classifyTyCons cs groups
keep_dcs = concatMap tyConDataCons keep_tcs
zipWithM_ defTyCon keep_tcs keep_tcs
zipWithM_ defDataCon keep_dcs keep_dcs
+
new_tcs <- vectTyConDecls conv_tcs
let orig_tcs = keep_tcs ++ conv_tcs
mk_map env = listToUFM_Directly [(u, getUnique n /= u) | (u,n) <- nameEnvUniqueElts env]
+-- | Vectorise some (possibly recursively defined) type constructors.
vectTyConDecls :: [TyCon] -> VM [TyCon]
vectTyConDecls tcs = fixV $ \tcs' ->
do
liftDs $ buildDataCon name'
False -- not infix
- (map (const NotMarkedStrict) arg_tys)
+ (map (const HsNoBang) arg_tys)
[] -- no labelled fields
univ_tvs
[] -- no existential tvs for now
liftDs $ buildDataCon dc_name
False -- not infix
- (map (const NotMarkedStrict) comp_tys)
+ (map (const HsNoBang) comp_tys)
[] -- no field labels
tvs
[] -- no existentials
raw_worker <- cloneId mkVectOcc orig_worker (exprType body)
let vect_worker = raw_worker `setIdUnfolding`
- mkInlineRule needSaturated body arity
+ mkInlineRule body (Just arity)
defGlobalVar orig_worker vect_worker
return (vect_worker, body)
where
method_ids <- mapM (method args) paMethods
pa_tc <- builtin paTyCon
- pa_con <- builtin paDataCon
+ pa_dc <- builtin paDataCon
let dict = mkLams (tvs ++ args)
- $ mkConApp pa_con
+ $ mkConApp pa_dc
$ Type inst_ty : map (method_call args) method_ids
dfun_ty = mkForAllTys tvs
$ mkFunTys (map varType args) (mkTyConApp pa_tc [inst_ty])
raw_dfun <- newExportedVar dfun_name dfun_ty
- let dfun = raw_dfun `setIdUnfolding` mkDFunUnfolding pa_con method_ids
+ let dfun = raw_dfun `setIdUnfolding` mkDFunUnfolding dfun_ty (map Var method_ids)
`setInlinePragma` dfunInlinePragma
hoistBinding dfun dict
let body = mkLams (tvs ++ args) expr
raw_var <- newExportedVar (method_name name) (exprType body)
let var = raw_var
- `setIdUnfolding` mkInlineRule needSaturated body (length args)
+ `setIdUnfolding` mkInlineRule body (Just (length args))
+ `setInlinePragma` alwaysInlinePragma
hoistBinding var body
return var
("fromArrPRepr", buildFromArrPRepr)]
-- | Split the given tycons into two sets depending on whether they have to be
--- converted (first list) or not (second list). The first argument contains
--- information about the conversion status of external tycons:
+-- converted (first list) or not (second list). The first argument contains
+-- information about the conversion status of external tycons:
--
-- * tycons which have converted versions are mapped to True
-- * tycons which are not changed by vectorisation are mapped to False