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, DsMatchContext, pprDsWarnings ) where
13 import HsSyn ( HsBinds, HsExpr )
14 import TcHsSyn ( SYN_IE(TypecheckedHsBinds), SYN_IE(TypecheckedHsExpr) )
18 import DsBinds ( dsBinds, dsInstBinds )
21 import Bag ( unionBags )
22 import CmdLineOpts ( opt_DoCoreLinting, opt_AutoSccsOnAllToplevs, opt_AutoSccsOnExportedToplevs )
23 import CoreLift ( liftCoreBindings )
24 import CoreLint ( lintCoreBindings )
25 import Id ( nullIdEnv, mkIdEnv )
26 import PprStyle ( PprStyle(..) )
27 import UniqSupply ( splitUniqSupply )
30 The only trick here is to get the @DsMonad@ stuff off to a good
34 deSugar :: UniqSupply -- name supply
35 -> FAST_STRING -- module name
37 -> (TypecheckedHsBinds, -- input: recsel, class, instance, and value
38 TypecheckedHsBinds, -- bindings; see "tcModule" (which produces
39 TypecheckedHsBinds, -- them)
41 [(Id, TypecheckedHsExpr)])
42 -- ToDo: handling of const_inst thingies is certainly WRONG ***************************
44 -> ([CoreBinding], -- output
45 Bag DsMatchContext) -- Shadowing complaints
47 deSugar us mod_name (recsel_binds, clas_binds, inst_binds, val_binds, const_inst_pairs)
49 (us0, us0a) = splitUniqSupply us
50 (us1, us1a) = splitUniqSupply us0a
51 (us2, us2a) = splitUniqSupply us1a
52 (us3, us3a) = splitUniqSupply us2a
53 (us4, us5) = splitUniqSupply us3a
55 auto_meth = opt_AutoSccsOnAllToplevs
56 auto_top = opt_AutoSccsOnAllToplevs
57 || opt_AutoSccsOnExportedToplevs
59 ((core_const_prs, consts_pairs), shadows1)
60 = initDs us0 nullIdEnv mod_name (dsInstBinds [] const_inst_pairs)
62 consts_env = mkIdEnv consts_pairs
64 (core_clas_binds, shadows2)
65 = initDs us1 consts_env mod_name (dsBinds False clas_binds)
66 core_clas_prs = pairsFromCoreBinds core_clas_binds
68 (core_inst_binds, shadows3)
69 = initDs us2 consts_env mod_name (dsBinds auto_meth inst_binds)
70 core_inst_prs = pairsFromCoreBinds core_inst_binds
72 (core_val_binds, shadows4)
73 = initDs us3 consts_env mod_name (dsBinds auto_top val_binds)
74 core_val_pairs = pairsFromCoreBinds core_val_binds
76 (core_recsel_binds, shadows5)
77 = initDs us4 consts_env mod_name (dsBinds ({-trace "Desugar:core_recsel_binds"-} False) recsel_binds)
78 core_recsel_prs = pairsFromCoreBinds core_recsel_binds
81 = if (null core_clas_prs && null core_inst_prs
82 && null core_recsel_prs {-???dont know???-} && null core_const_prs) then
83 -- we don't have to make the whole thing recursive
84 core_clas_binds ++ core_val_binds
86 else -- gotta make it recursive (sigh)
87 [Rec (core_clas_prs ++ core_inst_prs
88 ++ core_const_prs ++ core_val_pairs ++ core_recsel_prs)]
90 lift_final_binds = liftCoreBindings us5 final_binds
92 really_final_binds = if opt_DoCoreLinting
93 then lintCoreBindings PprDebug "Desugarer" False lift_final_binds
96 shadows = shadows1 `unionBags` shadows2 `unionBags`
97 shadows3 `unionBags` shadows4 `unionBags` shadows5
99 (really_final_binds, shadows)