- -> (a, DsWarnings)
-
-initDs dflags init_us (hst,pcs,local_type_env) mod action
- = action dflags init_us lookup noSrcLoc mod emptyBag
- where
- -- This lookup 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
- pte = pcs_PTE pcs
- lookup n = case lookupType hst pte n of {
- Just (AnId v) -> v ;
- other ->
- case lookupNameEnv local_type_env n of
- Just (AnId v) -> v ;
- other -> pprPanic "initDS: lookup:" (ppr n)
- }
-
-thenDs :: DsM a -> (a -> DsM b) -> DsM b
-andDs :: (a -> a -> a) -> DsM a -> DsM a -> DsM a
-
-thenDs m1 m2 dflags us genv loc mod warns
- = case splitUniqSupply us of { (s1, s2) ->
- case (m1 dflags s1 genv loc mod warns) of { (result, warns1) ->
- m2 result dflags s2 genv loc mod warns1}}
-
-andDs combiner m1 m2 dflags us genv loc mod warns
- = case splitUniqSupply us of { (s1, s2) ->
- case (m1 dflags s1 genv loc mod warns) of { (result1, warns1) ->
- case (m2 dflags s2 genv loc mod warns1) of { (result2, warns2) ->
- (combiner result1 result2, warns2) }}}
-
-returnDs :: a -> DsM a
-returnDs result dflags us genv loc mod 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)
-
-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