-mkWrapperArgTypeCategories
- :: Type -- wrapper's type
- -> [Demand] -- info about its arguments
- -> String -- a string saying lots about the args
-
-mkWrapperArgTypeCategories wrapper_ty wrap_info
- = case (splitFunTyExpandingDicts wrapper_ty) of { (arg_tys,_) ->
- map do_one (wrap_info `zip` (map showTypeCategory arg_tys)) }
- where
- -- ToDo: this needs FIXING UP (it was a hack anyway...)
- do_one (WwPrim, _) = 'P'
- do_one (WwEnum, _) = 'E'
- do_one (WwStrict, arg_ty_char) = arg_ty_char
- do_one (WwUnpack _, arg_ty_char)
- = if arg_ty_char `elem` "CIJFDTS"
- then toLower arg_ty_char
- else if arg_ty_char == '+' then 't'
- else trace ("mkWrapp..:funny char:"++[arg_ty_char]) '-'
- do_one (other_wrap_info, _) = '-'
-\end{code}
-
-Whether a worker exists depends on whether the worker has an
-absent argument, a @WwUnpack@ argument, (or @WwEnum@ ToDo???) arguments.
-
-If a @WwUnpack@ argument is for an {\em abstract} type (or one that
-will be abstract outside this module), which might happen for an
-imported function, then we can't (or don't want to...) unpack the arg
-as the worker requires. Hence we have to give up altogether, and call
-the wrapper only; so under these circumstances we return \tr{False}.
-
-\begin{code}
-#ifdef REALLY_HASKELL_1_3
-instance Read Demand where
-#else
-instance Text Demand where
-#endif
- readList str = read_em [{-acc-}] str
- where
- read_em acc [] = [(reverse acc, "")]
- -- lower case indicates absence...
- read_em acc ('L' : xs) = read_em (WwLazy False : acc) xs
- read_em acc ('A' : xs) = read_em (WwLazy True : acc) xs
- read_em acc ('S' : xs) = read_em (WwStrict : acc) xs
- read_em acc ('P' : xs) = read_em (WwPrim : acc) xs
- read_em acc ('E' : xs) = read_em (WwEnum : acc) xs
-
- read_em acc (')' : xs) = [(reverse acc, xs)]
- read_em acc ( 'U' : '(' : xs)
- = case (read_em [] xs) of
- [(stuff, rest)] -> read_em (WwUnpack stuff : acc) rest
- _ -> panic ("Text.Demand:"++str++"::"++xs)
-
- read_em acc other = panic ("IdInfo.readem:"++other)
-
-#ifdef REALLY_HASKELL_1_3
-instance Show Demand where
-#endif
- showList wrap_args rest = (concat (map show1 wrap_args)) ++ rest
- where
- show1 (WwLazy False) = "L"
- show1 (WwLazy True) = "A"
- show1 WwStrict = "S"
- show1 WwPrim = "P"
- show1 WwEnum = "E"
- show1 (WwUnpack args)= "U(" ++ (concat (map show1 args)) ++ ")"
-
-instance Outputable Demand where
- ppr sty si = ppStr (showList [si] "")
-
-instance OptIdInfo StrictnessInfo where
- noInfo = NoStrictnessInfo
-
- getInfo (IdInfo _ _ _ strict _ _ _ _ _ _) = strict
-
- addInfo id_info NoStrictnessInfo = id_info
- addInfo (IdInfo a b d _ e f g h i j) strict = IdInfo a b d strict e f g h i j
-
- ppInfo sty better_id_fn strictness_info
- = pp_strictness sty Nothing better_id_fn nullIdEnv strictness_info
-\end{code}
-
-We'll omit the worker info if the thing has an explicit unfolding
-already.
-\begin{code}
-pp_strictness sty _ _ _ NoStrictnessInfo = ifPprInterface sty pp_NONE
-
-pp_strictness sty _ _ _ BottomGuaranteed = ppPStr SLIT("_S_ _!_")
-
-pp_strictness sty for_this_id_maybe better_id_fn inline_env
- info@(StrictnessInfo wrapper_args wrkr_maybe)
- = let
- (have_wrkr, wrkr_id) = case wrkr_maybe of
- Nothing -> (False, panic "ppInfo(Strictness)")
- Just xx -> (True, xx)
-
- wrkr_to_print = better_id_fn wrkr_id
- wrkr_info = getIdInfo wrkr_to_print
-
- -- if we aren't going to be able to *read* the strictness info
- -- in TcPragmas, we need not even print it.
- wrapper_args_to_use
- = if not (indicatesWorker wrapper_args) then
- wrapper_args -- no worker/wrappering in any case
- else
- case for_this_id_maybe of
- Nothing -> wrapper_args
- Just id -> if externallyVisibleId id
- && (unfoldingUnfriendlyId id || not have_wrkr) then
- -- pprTrace "IdInfo: unworker-ising:" (ppCat [ppr PprDebug have_wrkr, ppr PprDebug id]) $
- map un_workerise wrapper_args
- else
- wrapper_args
-
- id_is_worker
- = case for_this_id_maybe of
- Nothing -> False
- Just id -> isWorkerId id
-
- am_printing_iface = case sty of { PprInterface -> True ; _ -> False }
-
- pp_basic_info
- = ppBesides [ppStr "_S_ \"",
- ppStr (showList wrapper_args_to_use ""), ppStr "\""]
-
- pp_with_worker
- = ppBesides [ ppSP, ppChar '{',
- ppIdInfo sty wrkr_to_print True{-wrkr specs, yes!-} better_id_fn inline_env wrkr_info,
- ppChar '}' ]
- in
- if all_present_WwLazies wrapper_args_to_use then -- too boring
- ifPprInterface sty pp_NONE
-
- else if id_is_worker && am_printing_iface then
- pp_NONE -- we don't put worker strictness in interfaces
- -- (it can be deduced)
-
- else if not (indicatesWorker wrapper_args_to_use)
- || not have_wrkr
- || boringIdInfo wrkr_info then
- ppBeside pp_basic_info ppNil
- else
- ppBeside pp_basic_info pp_with_worker
- where
- un_workerise (WwLazy _) = WwLazy False -- avoid absence
- un_workerise (WwUnpack _) = WwStrict
- un_workerise other = other
-\end{code}
-
-%************************************************************************
-%* *
-\subsection[unfolding-IdInfo]{Unfolding info about an @Id@}
-%* *
-%************************************************************************
-
-\begin{code}
-mkUnfolding guide expr
- = GenForm (mkFormSummary NoStrictnessInfo expr)
- (occurAnalyseGlobalExpr expr)
- guide
-\end{code}
-
-\begin{code}
-noInfo_UF = NoUnfoldingDetails
-
-getInfo_UF (IdInfo _ _ _ _ unfolding _ _ _ _ _)
- = case unfolding of
- GenForm _ _ BadUnfolding -> NoUnfoldingDetails
- unfolding_as_was -> unfolding_as_was
-
--- getInfo_UF ensures that any BadUnfoldings are never returned
--- We had to delay the test required in TcPragmas until now due
--- to strictness constraints in TcPragmas
-
-addInfo_UF id_info@(IdInfo a b c d e f g h i j) NoUnfoldingDetails = id_info
-addInfo_UF (IdInfo a b d e _ f g h i j) uf = IdInfo a b d e uf f g h i j