Create a deterministic version of tyVarsOfType
[ghc.git] / compiler / coreSyn / CoreSeq.hs
1 -- |
2 -- Various utilities for forcing Core structures
3 --
4 -- It can often be useful to force various parts of the AST. This module
5 -- provides a number of @seq@-like functions to accomplish this.
6
7 module CoreSeq (
8 -- * Utilities for forcing Core structures
9 seqExpr, seqExprs, seqUnfolding, seqRules,
10 megaSeqIdInfo, seqRuleInfo, seqBinds,
11 ) where
12
13 import CoreSyn
14 import IdInfo
15 import Demand( seqDemand, seqStrictSig )
16 import BasicTypes( seqOccInfo )
17 import VarSet( seqDVarSet )
18 import Var( varType, tyVarKind )
19 import Type( seqType, isTyVar )
20 import Coercion( seqCo )
21 import Id( Id, idInfo )
22
23 -- | Evaluate all the fields of the 'IdInfo' that are generally demanded by the
24 -- compiler
25 megaSeqIdInfo :: IdInfo -> ()
26 megaSeqIdInfo info
27 = seqRuleInfo (ruleInfo info) `seq`
28
29 -- Omitting this improves runtimes a little, presumably because
30 -- some unfoldings are not calculated at all
31 -- seqUnfolding (unfoldingInfo info) `seq`
32
33 seqDemand (demandInfo info) `seq`
34 seqStrictSig (strictnessInfo info) `seq`
35 seqCaf (cafInfo info) `seq`
36 seqOneShot (oneShotInfo info) `seq`
37 seqOccInfo (occInfo info)
38
39 seqOneShot :: OneShotInfo -> ()
40 seqOneShot l = l `seq` ()
41
42 seqRuleInfo :: RuleInfo -> ()
43 seqRuleInfo (RuleInfo rules fvs) = seqRules rules `seq` seqDVarSet fvs
44
45 seqCaf :: CafInfo -> ()
46 seqCaf c = c `seq` ()
47
48 seqRules :: [CoreRule] -> ()
49 seqRules [] = ()
50 seqRules (Rule { ru_bndrs = bndrs, ru_args = args, ru_rhs = rhs } : rules)
51 = seqBndrs bndrs `seq` seqExprs (rhs:args) `seq` seqRules rules
52 seqRules (BuiltinRule {} : rules) = seqRules rules
53
54 seqExpr :: CoreExpr -> ()
55 seqExpr (Var v) = v `seq` ()
56 seqExpr (Lit lit) = lit `seq` ()
57 seqExpr (App f a) = seqExpr f `seq` seqExpr a
58 seqExpr (Lam b e) = seqBndr b `seq` seqExpr e
59 seqExpr (Let b e) = seqBind b `seq` seqExpr e
60 seqExpr (Case e b t as) = seqExpr e `seq` seqBndr b `seq` seqType t `seq` seqAlts as
61 seqExpr (Cast e co) = seqExpr e `seq` seqCo co
62 seqExpr (Tick n e) = seqTickish n `seq` seqExpr e
63 seqExpr (Type t) = seqType t
64 seqExpr (Coercion co) = seqCo co
65
66 seqExprs :: [CoreExpr] -> ()
67 seqExprs [] = ()
68 seqExprs (e:es) = seqExpr e `seq` seqExprs es
69
70 seqTickish :: Tickish Id -> ()
71 seqTickish ProfNote{ profNoteCC = cc } = cc `seq` ()
72 seqTickish HpcTick{} = ()
73 seqTickish Breakpoint{ breakpointFVs = ids } = seqBndrs ids
74 seqTickish SourceNote{} = ()
75
76 seqBndr :: CoreBndr -> ()
77 seqBndr b | isTyVar b = seqType (tyVarKind b)
78 | otherwise = seqType (varType b) `seq`
79 megaSeqIdInfo (idInfo b)
80
81 seqBndrs :: [CoreBndr] -> ()
82 seqBndrs [] = ()
83 seqBndrs (b:bs) = seqBndr b `seq` seqBndrs bs
84
85 seqBinds :: [Bind CoreBndr] -> ()
86 seqBinds bs = foldr (seq . seqBind) () bs
87
88 seqBind :: Bind CoreBndr -> ()
89 seqBind (NonRec b e) = seqBndr b `seq` seqExpr e
90 seqBind (Rec prs) = seqPairs prs
91
92 seqPairs :: [(CoreBndr, CoreExpr)] -> ()
93 seqPairs [] = ()
94 seqPairs ((b,e):prs) = seqBndr b `seq` seqExpr e `seq` seqPairs prs
95
96 seqAlts :: [CoreAlt] -> ()
97 seqAlts [] = ()
98 seqAlts ((c,bs,e):alts) = c `seq` seqBndrs bs `seq` seqExpr e `seq` seqAlts alts
99
100 seqUnfolding :: Unfolding -> ()
101 seqUnfolding (CoreUnfolding { uf_tmpl = e, uf_is_top = top,
102 uf_is_value = b1, uf_is_work_free = b2,
103 uf_expandable = b3, uf_is_conlike = b4,
104 uf_guidance = g})
105 = seqExpr e `seq` top `seq` b1 `seq` b2 `seq` b3 `seq` b4 `seq` seqGuidance g
106
107 seqUnfolding _ = ()
108
109 seqGuidance :: UnfoldingGuidance -> ()
110 seqGuidance (UnfIfGoodArgs ns n b) = n `seq` sum ns `seq` b `seq` ()
111 seqGuidance _ = ()