- -> (a, DsWarnings)
-
-initDs dflags init_us lookup mod (DsM action)
- = initUs_ init_us (action ds_env emptyBag)
- where
- ds_env = DsEnv { ds_dflags = dflags, ds_globals = lookup,
- ds_loc = noSrcLoc, ds_mod = mod,
- ds_meta = emptyNameEnv }
-
-thenDs :: DsM a -> (a -> DsM b) -> DsM b
-
-thenDs (DsM m1) m2 = DsM( \ env warns ->
- m1 env warns `thenUs` \ (result, warns1) ->
- unDsM (m2 result) env warns1)
-
-returnDs :: a -> DsM a
-returnDs result = DsM (\ env warns -> returnUs (result, warns))
-
-fixDs :: (a -> DsM a) -> DsM a
-fixDs f = DsM (\env warns -> fixUs (\ ~(a, _warns') -> unDsM (f a) env 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)
-
-foldlDs :: (a -> b -> DsM a) -> a -> [b] -> DsM a
-
-foldlDs k z [] = returnDs z
-foldlDs k z (x:xs) = k z x `thenDs` \ r ->
- foldlDs k r xs
-
-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 [] ys = returnDs []
-zipWithDs f (x:xs) (y:ys)
- = f x y `thenDs` \ r ->
- zipWithDs f xs ys `thenDs` \ rs ->
- returnDs (r:rs)
+ -> 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