- -> (a, DsWarnings)
-
-initDs init_us env mod_name action
- = action init_us mkUnknownSrcLoc module_and_group env emptyBag
- where
- module_and_group = (mod_name, grp_name)
- grp_name = case opt_SccGroup of
- Just xx -> _PK_ xx
- Nothing -> mod_name -- default: module name
-
-thenDs :: DsM a -> (a -> DsM b) -> DsM b
-andDs :: (a -> a -> a) -> DsM a -> DsM a -> DsM a
-
-thenDs m1 m2 us loc mod_and_grp env warns
- = case splitUniqSupply us of { (s1, s2) ->
- case (m1 s1 loc mod_and_grp env warns) of { (result, warns1) ->
- m2 result s2 loc mod_and_grp env warns1}}
-
-andDs combiner m1 m2 us loc mod_and_grp env warns
- = case splitUniqSupply us of { (s1, s2) ->
- case (m1 s1 loc mod_and_grp env warns) of { (result1, warns1) ->
- case (m2 s2 loc mod_and_grp env warns1) of { (result2, warns2) ->
- (combiner result1 result2, warns2) }}}
-
-returnDs :: a -> DsM a
-returnDs result us loc mod_and_grp env warns = (result, warns)
-
-listDs :: [DsM a] -> DsM [a]
-listDs [] = returnDs []
-listDs (x:xs)
- = x `thenDs` \ r ->
- listDs xs `thenDs` \ rs ->
- returnDs (r:rs)
-
-mapDs :: (a -> DsM b) -> [a] -> DsM [b]
-
-mapDs f [] = returnDs []
-mapDs f (x:xs)
- = f x `thenDs` \ r ->
- mapDs f xs `thenDs` \ rs ->
- returnDs (r:rs)
-
-mapAndUnzipDs :: (a -> DsM (b, c)) -> [a] -> DsM ([b], [c])
-
-mapAndUnzipDs f [] = returnDs ([], [])
-mapAndUnzipDs f (x:xs)
- = f x `thenDs` \ (r1, r2) ->
- mapAndUnzipDs f xs `thenDs` \ (rs1, rs2) ->
- returnDs (r1:rs1, r2:rs2)
-
-zipWithDs :: (a -> b -> DsM c) -> [a] -> [b] -> DsM [c]
-
-zipWithDs f [] [] = returnDs []
-zipWithDs f (x:xs) (y:ys)
- = f x y `thenDs` \ r ->
- zipWithDs f xs ys `thenDs` \ rs ->
- returnDs (r:rs)
--- Note: crashes if lists not equal length (like zipWithEqual)
+ -> IO (a, Bag WarnMsg)
+
+initDs hsc_env mod rdr_env type_env thing_inside
+ = do { warn_var <- newIORef emptyBag
+ ; let { if_genv = IfGblEnv { if_rec_types = Just (mod, return type_env) }
+ ; if_lenv = mkIfLclEnv mod (ptext SLIT("GHC error in desugarer lookup in") <+> ppr mod)
+ ; gbl_env = DsGblEnv { ds_mod = mod,
+ ds_if_env = (if_genv, if_lenv),
+ ds_warns = warn_var }
+ ; lcl_env = DsLclEnv { ds_meta = emptyNameEnv,
+ ds_loc = noSrcSpan } }
+
+ ; res <- initTcRnIf 'd' hsc_env gbl_env lcl_env thing_inside
+
+ ; warns <- readIORef warn_var
+ ; return (res, mapBag mk_warn warns)
+ }
+ where
+ print_unqual = unQualInScope rdr_env
+
+ mk_warn :: (SrcSpan,SDoc) -> WarnMsg
+ mk_warn (loc,sdoc) = mkWarnMsg loc print_unqual sdoc