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 and type synonyms).
15 #include "HsVersions.h"
17 module HsPragmas where
22 import HsLoop ( ConDecl )
23 import HsCore ( UnfoldingCoreExpr )
24 import HsTypes ( MonoType )
28 import Outputable ( Outputable(..){-instances-} )
32 Certain pragmas expect to be pinned onto certain constructs.
34 Pragma types may be parameterised, just as with any other
37 For a @data@ declaration---makes visible the constructors for an
38 abstract @data@ type and indicates which specialisations exist.
41 = DataPragmas [ConDecl name] -- hidden data constructors
42 [[Maybe (MonoType name)]] -- types to which specialised
45 These are {\em general} things you can know about any value:
49 | GenPragmas (Maybe Int) -- arity (maybe)
50 (Maybe UpdateInfo) -- update info (maybe)
51 DeforestInfo -- deforest info
52 (ImpStrictness name) -- strictness, worker-wrapper
53 (ImpUnfolding name) -- unfolding (maybe)
54 [([Maybe (MonoType name)], -- Specialisations: types to which spec'd;
55 Int, -- # dicts to ignore
56 GenPragmas name)] -- Gen info about the spec'd version
58 noGenPragmas = NoGenPragmas
60 data ImpUnfolding name
62 | ImpMagicUnfolding FAST_STRING -- magic "unfolding"
63 -- known to the compiler by "String"
64 | ImpUnfolding UnfoldingGuidance -- always, if you like, etc.
65 (UnfoldingCoreExpr name)
67 data ImpStrictness name
69 | ImpStrictness Bool -- True <=> bottoming Id
70 [Demand] -- demand info
71 (GenPragmas name) -- about the *worker*
74 For an ordinary imported function: it can have general pragmas (only).
76 For a class's super-class dictionary selectors:
78 data ClassPragmas name
80 | SuperDictPragmas [GenPragmas name] -- list mustn't be empty
83 For a class's method selectors:
85 data ClassOpPragmas name
87 | ClassOpPragmas (GenPragmas name) -- for method selector
88 (GenPragmas name) -- for default method
90 noClassOpPragmas = NoClassOpPragmas
94 data InstancePragmas name
97 | SimpleInstancePragma -- nothing but for the dfun itself...
100 | ConstantInstancePragma
101 (GenPragmas name) -- for the "dfun" itself
102 [(name, GenPragmas name)] -- one per class op
104 | SpecialisedInstancePragma
105 (GenPragmas name) -- for its "dfun"
106 [([Maybe (MonoType name)], -- specialised instance; type...
107 Int, -- #dicts to ignore
108 InstancePragmas name)] -- (no SpecialisedInstancePragma please!)
111 Some instances for printing (just for debugging, really)
113 instance Outputable name => Outputable (ClassPragmas name) where
114 ppr sty NoClassPragmas = ppNil
115 ppr sty (SuperDictPragmas sdsel_prags)
116 = ppAbove (ppStr "{-superdict pragmas-}")
117 (ppr sty sdsel_prags)
119 instance Outputable name => Outputable (ClassOpPragmas name) where
120 ppr sty NoClassOpPragmas = ppNil
121 ppr sty (ClassOpPragmas op_prags defm_prags)
122 = ppAbove (ppCat [ppStr "{-meth-}", ppr sty op_prags])
123 (ppCat [ppStr "{-defm-}", ppr sty defm_prags])
125 instance Outputable name => Outputable (InstancePragmas name) where
126 ppr sty NoInstancePragmas = ppNil
127 ppr sty (SimpleInstancePragma dfun_pragmas)
128 = ppCat [ppStr "{-dfun-}", ppr sty dfun_pragmas]
129 ppr sty (ConstantInstancePragma dfun_pragmas name_pragma_pairs)
130 = ppAbove (ppCat [ppStr "{-constm-}", ppr sty dfun_pragmas])
131 (ppAboves (map pp_pair name_pragma_pairs))
134 = ppCat [ppr sty n, ppEquals, ppr sty prags]
136 ppr sty (SpecialisedInstancePragma dfun_pragmas spec_pragma_info)
137 = ppAbove (ppCat [ppStr "{-spec'd-}", ppr sty dfun_pragmas])
138 (ppAboves (map pp_info spec_pragma_info))
140 pp_info (ty_maybes, num_dicts, prags)
141 = ppBesides [ppLbrack, ppInterleave ppSP (map pp_ty ty_maybes), ppRbrack,
142 ppLparen, ppInt num_dicts, ppRparen, ppEquals, ppr sty prags]
143 pp_ty Nothing = ppStr "_N_"
144 pp_ty (Just t)= ppr sty t
146 instance Outputable name => Outputable (GenPragmas name) where
147 ppr sty NoGenPragmas = ppNil
148 ppr sty (GenPragmas arity_maybe upd_maybe def strictness unfolding specs)
149 = ppCat [pp_arity arity_maybe, pp_upd upd_maybe, -- ToDo: print def?
150 pp_str strictness, pp_unf unfolding,
153 pp_arity Nothing = ppNil
154 pp_arity (Just i) = ppBeside (ppStr "ARITY=") (ppInt i)
156 pp_upd Nothing = ppNil
157 pp_upd (Just u) = ppInfo sty id u
159 pp_str NoImpStrictness = ppNil
160 pp_str (ImpStrictness is_bot demands wrkr_prags)
161 = ppBesides [ppStr "IS_BOT=", ppr sty is_bot,
162 ppStr "STRICTNESS=", ppStr (showList demands ""),
163 ppStr " {", ppr sty wrkr_prags, ppStr "}"]
165 pp_unf NoImpUnfolding = ppStr "NO_UNFOLDING"
166 pp_unf (ImpMagicUnfolding m) = ppBeside (ppStr "MAGIC=") (ppPStr m)
167 pp_unf (ImpUnfolding g core) = ppBeside (ppStr "UNFOLD=") (ppr sty core)
171 = ppBesides [ppStr "SPECS=[", ppInterleave ppSP (map pp_spec specs), ppStr "]"]
173 pp_spec (ty_maybes, num_dicts, gprags)
174 = ppCat [ppLbrack, ppInterleave ppSP (map pp_MaB ty_maybes), ppRbrack, ppInt num_dicts, ppr sty gprags]
176 pp_MaB Nothing = ppStr "_N_"
177 pp_MaB (Just x) = ppr sty x