+ ; endPass dflags "Desugar" Opt_D_dump_ds ds_binds
+
+ -- Dump output
+ ; doIfSet (dopt Opt_D_dump_ds dflags)
+ (printDump (ppr_ds_rules ds_rules))
+
+ ; let
+ deps = Deps { dep_mods = moduleEnvElts (imp_dep_mods imports),
+ dep_pkgs = imp_dep_pkgs imports,
+ dep_orphs = imp_orphs imports }
+ mod_guts = ModGuts {
+ mg_module = mod,
+ mg_exports = exports,
+ mg_deps = deps,
+ mg_usages = mkUsageInfo hsc_env eps imports usages,
+ mg_dir_imps = [m | (m,_) <- moduleEnvElts (imp_mods imports)],
+ mg_rdr_env = rdr_env,
+ mg_fix_env = fix_env,
+ mg_deprecs = deprecs,
+ mg_types = type_env,
+ mg_insts = insts,
+ mg_rules = ds_rules,
+ mg_binds = ds_binds,
+ mg_foreign = ds_fords }
+
+ ; return mod_guts
+ }
+
+ where
+ dflags = hsc_dflags hsc_env
+ print_unqual = unQualInScope rdr_env
+
+ -- Desugarer warnings are SDocs; here we
+ -- add the info about whether or not to print unqualified
+ mk_warn :: (SrcLoc,SDoc) -> (SrcLoc, Pretty.Doc)
+ mk_warn (loc, sdoc) = addShortWarnLocLine loc print_unqual sdoc
+
+ -- The lookup function passed to initDs is used for well-known Ids,
+ -- such as fold, build, cons etc, so the chances are
+ -- it'll be found in the package symbol table. That's
+ -- why we don't merge all these tables
+ eps = pcs_EPS pcs
+ pte = eps_PTE eps
+ hpt = hsc_HPT hsc_env
+ lookup n = case lookupType hpt pte n of {
+ Just v -> v ;
+ other ->
+ case lookupNameEnv type_env n of
+ Just v -> v ;
+ other -> pprPanic "Desugar: lookup:" (ppr n)
+ }
+
+deSugarExpr :: HscEnv
+ -> PersistentCompilerState
+ -> Module -> GlobalRdrEnv -> TypeEnv
+ -> TypecheckedHsExpr
+ -> IO CoreExpr
+deSugarExpr hsc_env pcs this_mod rdr_env type_env tc_expr
+ = do { showPass dflags "Desugar"
+ ; us <- mkSplitUniqSupply 'd'
+
+ -- Do desugaring
+ ; let (core_expr, ds_warns) = initDs dflags us lookup this_mod (dsExpr tc_expr)
+ warn_doc = pprBagOfWarnings (mapBag mk_warn ds_warns)
+
+ -- Display any warnings
+ ; doIfSet (not (isEmptyBag ds_warns))
+ (printErrs warn_doc)