2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[Desugar]{@deSugar@: the main function}
7 #include "HsVersions.h"
9 module Desugar ( deSugar, pprDsWarnings
10 #if __GLASGOW_HASKELL__ < 200
12 , DsWarnFlavour -- fluff needed for closure,
13 -- removed when compiling with 1.4
19 import HsSyn ( HsBinds, HsExpr, MonoBinds,
20 SYN_IE(RecFlag), nonRecursive
22 import TcHsSyn ( SYN_IE(TypecheckedHsBinds), SYN_IE(TypecheckedHsExpr)
25 import Name ( isExported )
27 import DsBinds ( dsBinds )
30 import Bag ( unionBags )
31 import CmdLineOpts ( opt_DoCoreLinting, opt_SccGroup )
32 import CostCentre ( IsCafCC(..), mkAutoCC )
33 import CoreLift ( liftCoreBindings )
34 import CoreLint ( lintCoreBindings )
35 import Id ( nullIdEnv, mkIdEnv, idType,
36 SYN_IE(DictVar), GenId, SYN_IE(Id) )
37 import Outputable ( PprStyle(..) )
38 import UniqSupply ( splitUniqSupply, UniqSupply )
41 The only trick here is to get the @DsMonad@ stuff off to a good
45 deSugar :: UniqSupply -- name supply
46 -> FAST_STRING -- module name
48 -> (TypecheckedHsBinds, -- input: recsel, class, instance, and value
49 TypecheckedHsBinds, -- bindings; see "tcModule" (which produces
50 TypecheckedHsBinds, -- them)
53 -- ToDo: handling of const_inst thingies is certainly WRONG ***************************
55 -> ([CoreBinding], -- output
56 DsWarnings) -- Shadowing complaints
58 deSugar us mod_name (recsel_binds, clas_binds, inst_binds, val_binds, const_inst_binds)
60 (us0, us0a) = splitUniqSupply us
61 (us1, us1a) = splitUniqSupply us0a
62 (us2, us2a) = splitUniqSupply us1a
63 (us3, us3a) = splitUniqSupply us2a
64 (us4, us5) = splitUniqSupply us3a
67 module_and_group = (mod_name, grp_name)
68 grp_name = case opt_SccGroup of
70 Nothing -> mod_name -- default: module name
72 (core_const_binds, shadows1)
73 = initDs us0 nullIdEnv mod_name (dsBinds Nothing const_inst_binds)
74 core_const_prs = pairsFromCoreBinds core_const_binds
76 (core_clas_binds, shadows2)
77 = initDs us1 nullIdEnv mod_name (dsBinds Nothing clas_binds)
78 core_clas_prs = pairsFromCoreBinds core_clas_binds
80 (core_inst_binds, shadows3)
81 = initDs us2 nullIdEnv mod_name (dsBinds Nothing inst_binds)
82 core_inst_prs = pairsFromCoreBinds core_inst_binds
84 (core_val_binds, shadows4)
85 = initDs us3 nullIdEnv mod_name (dsBinds (Just module_and_group) val_binds)
86 core_val_pairs = pairsFromCoreBinds core_val_binds
88 (core_recsel_binds, shadows5)
89 = initDs us4 nullIdEnv mod_name (dsBinds Nothing recsel_binds)
90 core_recsel_prs = pairsFromCoreBinds core_recsel_binds
93 = if (null core_clas_prs && null core_inst_prs
94 && null core_recsel_prs {-???dont know???-} && null core_const_prs) then
95 -- we don't have to make the whole thing recursive
96 core_clas_binds ++ core_val_binds
98 else -- gotta make it recursive (sigh)
99 [Rec (core_clas_prs ++ core_inst_prs
100 ++ core_const_prs ++ core_val_pairs ++ core_recsel_prs)]
102 lift_final_binds = liftCoreBindings us5 final_binds
104 really_final_binds = if opt_DoCoreLinting
105 then lintCoreBindings PprDebug "Desugarer" False lift_final_binds
106 else lift_final_binds
108 shadows = shadows1 `unionBags` shadows2 `unionBags`
109 shadows3 `unionBags` shadows4 `unionBags` shadows5
111 (really_final_binds, shadows)