2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1996
4 %************************************************************************
6 \section[HsPragmas]{Pragmas in Haskell interface files}
8 %************************************************************************
10 See also: @Sig@ (``signatures'') which is where user-supplied pragmas
11 for values show up; ditto @SpecInstSig@ (for instances) and
12 @SpecDataSig@ (for data types).
15 #include "HsVersions.h"
17 module HsPragmas where
22 import HsCore ( UnfoldingCoreExpr )
23 import HsTypes ( MonoType )
27 import Outputable ( Outputable(..) )
31 Certain pragmas expect to be pinned onto certain constructs.
33 Pragma types may be parameterised, just as with any other
36 For a @data@ declaration---indicates which specialisations exist.
40 | DataPragmas [[Maybe (MonoType name)]] -- types to which specialised
42 noDataPragmas = NoDataPragmas
44 isNoDataPragmas NoDataPragmas = True
45 isNoDataPragmas _ = False
48 These are {\em general} things you can know about any value:
52 | GenPragmas (Maybe Int) -- arity (maybe)
53 (Maybe UpdateInfo) -- update info (maybe)
54 DeforestInfo -- deforest info
55 (ImpStrictness name) -- strictness, worker-wrapper
56 (ImpUnfolding name) -- unfolding (maybe)
57 [([Maybe (MonoType name)], -- Specialisations: types to which spec'd;
58 Int, -- # dicts to ignore
59 GenPragmas name)] -- Gen info about the spec'd version
61 noGenPragmas = NoGenPragmas
63 isNoGenPragmas NoGenPragmas = True
64 isNoGenPragmas _ = False
66 data ImpUnfolding name
68 | ImpMagicUnfolding FAST_STRING -- magic "unfolding"
69 -- known to the compiler by "String"
70 | ImpUnfolding UnfoldingGuidance -- always, if you like, etc.
71 (UnfoldingCoreExpr name)
73 data ImpStrictness name
75 | ImpStrictness Bool -- True <=> bottoming Id
76 [Demand] -- demand info
77 (GenPragmas name) -- about the *worker*
80 For an ordinary imported function: it can have general pragmas (only).
82 For a class's super-class dictionary selectors:
84 data ClassPragmas name
86 | SuperDictPragmas [GenPragmas name] -- list mustn't be empty
88 noClassPragmas = NoClassPragmas
90 isNoClassPragmas NoClassPragmas = True
91 isNoClassPragmas _ = False
94 For a class's method selectors:
96 data ClassOpPragmas name
98 | ClassOpPragmas (GenPragmas name) -- for method selector
99 (GenPragmas name) -- for default method
102 noClassOpPragmas = NoClassOpPragmas
104 isNoClassOpPragmas NoClassOpPragmas = True
105 isNoClassOpPragmas _ = False
109 data InstancePragmas name
112 | SimpleInstancePragma -- nothing but for the dfun itself...
115 | ConstantInstancePragma
116 (GenPragmas name) -- for the "dfun" itself
117 [(name, GenPragmas name)] -- one per class op
119 | SpecialisedInstancePragma
120 (GenPragmas name) -- for its "dfun"
121 [([Maybe (MonoType name)], -- specialised instance; type...
122 Int, -- #dicts to ignore
123 InstancePragmas name)] -- (no SpecialisedInstancePragma please!)
125 noInstancePragmas = NoInstancePragmas
127 isNoInstancePragmas NoInstancePragmas = True
128 isNoInstancePragmas _ = False
131 Some instances for printing (just for debugging, really)
133 instance Outputable name => Outputable (ClassPragmas name) where
134 ppr sty NoClassPragmas = ppNil
135 ppr sty (SuperDictPragmas sdsel_prags)
136 = ppAbove (ppStr "{-superdict pragmas-}")
137 (ppr sty sdsel_prags)
139 instance Outputable name => Outputable (ClassOpPragmas name) where
140 ppr sty NoClassOpPragmas = ppNil
141 ppr sty (ClassOpPragmas op_prags defm_prags)
142 = ppAbove (ppCat [ppStr "{-meth-}", ppr sty op_prags])
143 (ppCat [ppStr "{-defm-}", ppr sty defm_prags])
145 instance Outputable name => Outputable (InstancePragmas name) where
146 ppr sty NoInstancePragmas = ppNil
147 ppr sty (SimpleInstancePragma dfun_pragmas)
148 = ppCat [ppStr "{-dfun-}", ppr sty dfun_pragmas]
149 ppr sty (ConstantInstancePragma dfun_pragmas name_pragma_pairs)
150 = ppAbove (ppCat [ppStr "{-constm-}", ppr sty dfun_pragmas])
151 (ppAboves (map pp_pair name_pragma_pairs))
154 = ppCat [ppr sty n, ppEquals, ppr sty prags]
156 ppr sty (SpecialisedInstancePragma dfun_pragmas spec_pragma_info)
157 = ppAbove (ppCat [ppStr "{-spec'd-}", ppr sty dfun_pragmas])
158 (ppAboves (map pp_info spec_pragma_info))
160 pp_info (ty_maybes, num_dicts, prags)
161 = ppBesides [ppLbrack, ppInterleave ppSP (map pp_ty ty_maybes), ppRbrack,
162 ppLparen, ppInt num_dicts, ppRparen, ppEquals, ppr sty prags]
163 pp_ty Nothing = ppStr "_N_"
164 pp_ty (Just t)= ppr sty t
166 instance Outputable name => Outputable (GenPragmas name) where
167 ppr sty NoGenPragmas = ppNil
168 ppr sty (GenPragmas arity_maybe upd_maybe def strictness unfolding specs)
169 = ppCat [pp_arity arity_maybe, pp_upd upd_maybe, -- ToDo: print def?
170 pp_str strictness, pp_unf unfolding,
173 pp_arity Nothing = ppNil
174 pp_arity (Just i) = ppBeside (ppStr "ARITY=") (ppInt i)
176 pp_upd Nothing = ppNil
177 pp_upd (Just u) = ppInfo sty id u
179 pp_str NoImpStrictness = ppNil
180 pp_str (ImpStrictness is_bot demands wrkr_prags)
181 = ppBesides [ppStr "IS_BOT=", ppr sty is_bot,
182 ppStr "STRICTNESS=", ppStr (showList demands ""),
183 ppStr " {", ppr sty wrkr_prags, ppStr "}"]
185 pp_unf NoImpUnfolding = ppStr "NO_UNFOLDING"
186 pp_unf (ImpMagicUnfolding m) = ppBeside (ppStr "MAGIC=") (ppPStr m)
187 pp_unf (ImpUnfolding g core) = ppBeside (ppStr "UNFOLD=") (ppr sty core)
191 = ppBesides [ppStr "SPECS=[", ppInterleave ppSP (map pp_spec specs), ppStr "]"]
193 pp_spec (ty_maybes, num_dicts, gprags)
194 = ppCat [ppLbrack, ppInterleave ppSP (map pp_MaB ty_maybes), ppRbrack, ppInt num_dicts, ppr sty gprags]
196 pp_MaB Nothing = ppStr "_N_"
197 pp_MaB (Just x) = ppr sty x