2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1995
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 @SpecialisedInstanceSig@ (for instances) and
12 @DataTypeSig@ (for data types and type synonyms).
15 #include "HsVersions.h"
17 module HsPragmas where
19 import HsCore ( UnfoldingCoreExpr, UfCostCentre )
20 import HsDecls ( ConDecl )
21 import HsTypes ( MonoType, PolyType )
23 import Maybes ( Maybe(..) )
25 import Outputable -- class for printing, forcing
26 import Pretty -- pretty-printing utilities
27 import ProtoName ( ProtoName(..) ) -- .. is for pragmas only
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---makes visible the constructors for an
37 abstract @data@ type and indicates which specialisations exist.
40 = DataPragmas [ConDecl name] -- hidden data constructors
41 [[Maybe (MonoType name)]] -- types to which speciaised
43 type ProtoNameDataPragmas = DataPragmas ProtoName
44 type RenamedDataPragmas = DataPragmas Name
47 For a @type@ declaration---declare that it should be treated as
48 ``abstract'' (flag any use of its expansion as an error):
55 These are {\em general} things you can know about any value:
59 | GenPragmas (Maybe Int) -- arity (maybe)
60 (Maybe UpdateInfo) -- update info (maybe)
61 DeforestInfo -- deforest info
62 (ImpStrictness name) -- strictness, worker-wrapper
63 (ImpUnfolding name) -- unfolding (maybe)
64 [([Maybe (MonoType name)], -- Specialisations: types to which spec'd;
65 Int, -- # dicts to ignore
66 GenPragmas name)] -- Gen info about the spec'd version
68 type ProtoNameGenPragmas = GenPragmas ProtoName
69 type RenamedGenPragmas = GenPragmas Name
71 data ImpUnfolding name
73 | ImpMagicUnfolding FAST_STRING -- magic "unfolding"
74 -- known to the compiler by "String"
75 | ImpUnfolding UnfoldingGuidance -- always, if you like, etc.
76 (UnfoldingCoreExpr name)
78 type ProtoNameUnfoldingCoreExpr = UnfoldingCoreExpr ProtoName
80 data ImpStrictness name
82 | ImpStrictness Bool -- True <=> bottoming Id
83 [Demand] -- demand info
84 (GenPragmas name) -- about the *worker*
86 type RenamedImpStrictness = ImpStrictness Name
89 For an ordinary imported function: it can have general pragmas (only).
91 For a class's super-class dictionary selectors:
93 data ClassPragmas name
95 | SuperDictPragmas [GenPragmas name] -- list mustn't be empty
97 type ProtoNameClassPragmas = ClassPragmas ProtoName
98 type RenamedClassPragmas = ClassPragmas Name
101 For a class's method selectors:
103 data ClassOpPragmas name
105 | ClassOpPragmas (GenPragmas name) -- for method selector
106 (GenPragmas name) -- for default method
108 type ProtoNameClassOpPragmas = ClassOpPragmas ProtoName
109 type RenamedClassOpPragmas = ClassOpPragmas Name
113 data InstancePragmas name
116 | SimpleInstancePragma -- nothing but for the dfun itself...
119 | ConstantInstancePragma
120 (GenPragmas name) -- for the "dfun" itself
121 [(name, GenPragmas name)] -- one per class op
123 | SpecialisedInstancePragma
124 (GenPragmas name) -- for its "dfun"
125 [([Maybe (MonoType name)], -- specialised instance; type...
126 Int, -- #dicts to ignore
127 InstancePragmas name)] -- (no SpecialisedInstancePragma please!)
129 type ProtoNameInstancePragmas = InstancePragmas ProtoName
130 type RenamedInstancePragmas = InstancePragmas Name
133 Some instances for printing (just for debugging, really)
135 instance Outputable name => Outputable (ClassPragmas name) where
136 ppr sty NoClassPragmas = ppNil
137 ppr sty (SuperDictPragmas sdsel_prags)
138 = ppAbove (ppStr "{-superdict pragmas-}")
139 (ppr sty sdsel_prags)
141 instance Outputable name => Outputable (ClassOpPragmas name) where
142 ppr sty NoClassOpPragmas = ppNil
143 ppr sty (ClassOpPragmas op_prags defm_prags)
144 = ppAbove (ppCat [ppStr "{-meth-}", ppr sty op_prags])
145 (ppCat [ppStr "{-defm-}", ppr sty defm_prags])
147 instance Outputable name => Outputable (InstancePragmas name) where
148 ppr sty NoInstancePragmas = ppNil
149 ppr sty (SimpleInstancePragma dfun_pragmas)
150 = ppCat [ppStr "{-dfun-}", ppr sty dfun_pragmas]
151 ppr sty (ConstantInstancePragma dfun_pragmas name_pragma_pairs)
152 = ppAbove (ppCat [ppStr "{-constm-}", ppr sty dfun_pragmas])
153 (ppAboves (map pp_pair name_pragma_pairs))
156 = ppCat [ppr sty n, ppEquals, ppr sty prags]
158 ppr sty (SpecialisedInstancePragma dfun_pragmas spec_pragma_info)
159 = ppAbove (ppCat [ppStr "{-spec'd-}", ppr sty dfun_pragmas])
160 (ppAboves (map pp_info spec_pragma_info))
162 pp_info (ty_maybes, num_dicts, prags)
163 = ppBesides [ppLbrack, ppInterleave ppSP (map pp_ty ty_maybes), ppRbrack,
164 ppLparen, ppInt num_dicts, ppRparen, ppEquals, ppr sty prags]
165 pp_ty Nothing = ppStr "_N_"
166 pp_ty (Just t)= ppr sty t
168 instance Outputable name => Outputable (GenPragmas name) where
169 ppr sty NoGenPragmas = ppNil
170 ppr sty (GenPragmas arity_maybe upd_maybe def strictness unfolding specs)
171 = ppCat [pp_arity arity_maybe, pp_upd upd_maybe, -- ToDo: print def?
172 pp_str strictness, pp_unf unfolding,
175 pp_arity Nothing = ppNil
176 pp_arity (Just i) = ppBeside (ppStr "ARITY=") (ppInt i)
178 pp_upd Nothing = ppNil
179 pp_upd (Just u) = ppInfo sty id u
181 pp_str NoImpStrictness = ppNil
182 pp_str (ImpStrictness is_bot demands wrkr_prags)
183 = ppBesides [ppStr "IS_BOT=", ppr sty is_bot,
184 ppStr "STRICTNESS=", ppStr (showList demands ""),
185 ppStr " {", ppr sty wrkr_prags, ppStr "}"]
187 pp_unf NoImpUnfolding = ppStr "NO_UNFOLDING"
188 pp_unf (ImpMagicUnfolding m) = ppBeside (ppStr "MAGIC=") (ppPStr m)
189 pp_unf (ImpUnfolding g core) = ppBeside (ppStr "UNFOLD=") (ppr sty core)
193 = ppBesides [ppStr "SPECS=[", ppInterleave ppSP (map pp_spec specs), ppStr "]"]
195 pp_spec (ty_maybes, num_dicts, gprags)
196 = ppCat [ppLbrack, ppInterleave ppSP (map pp_MaB ty_maybes), ppRbrack, ppInt num_dicts, ppr sty gprags]
198 pp_MaB Nothing = ppStr "_N_"
199 pp_MaB (Just x) = ppr sty x