Skip to content

Commit 3e28de3

Browse files
committed
Add compatibility with GHC 7.8 and GHC 7.10
The changes to `src/Info.hs` are taken from the snapshot of the file at this commit: schell@9bd3dce Credit for these fixes goes to: https://github.com/schell https://github.com/rampion https://github.com/adituv
1 parent 0cd4776 commit 3e28de3

File tree

1 file changed

+49
-7
lines changed

1 file changed

+49
-7
lines changed

src/Info.hs

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ import qualified Desugar
1616
#if __GLASGOW_HASKELL__ >= 706
1717
import qualified DynFlags
1818
#endif
19+
#if __GLASGOW_HASKELL__ >= 708
20+
import qualified HsExpr
21+
#else
22+
import qualified TcRnTypes
23+
#endif
1924
import qualified GHC
2025
import qualified HscTypes
2126
import qualified NameSet
2227
import qualified Outputable
2328
import qualified PprTyThing
2429
import qualified Pretty
2530
import qualified TcHsSyn
26-
import qualified TcRnTypes
2731

2832
getIdentifierInfo :: FilePath -> String -> GHC.Ghc (Either String String)
2933
getIdentifierInfo file identifier =
@@ -127,21 +131,32 @@ getSrcSpan (GHC.RealSrcSpan spn) =
127131
getSrcSpan _ = Nothing
128132

129133
getTypeLHsBind :: GHC.TypecheckedModule -> GHC.LHsBind GHC.Id -> GHC.Ghc (Maybe (GHC.SrcSpan, GHC.Type))
134+
#if __GLASGOW_HASKELL__ >= 708
135+
getTypeLHsBind _ (GHC.L spn GHC.FunBind{GHC.fun_matches = grp}) = return $ Just (spn, HsExpr.mg_res_ty grp)
136+
#else
130137
getTypeLHsBind _ (GHC.L spn GHC.FunBind{GHC.fun_matches = GHC.MatchGroup _ typ}) = return $ Just (spn, typ)
138+
#endif
131139
getTypeLHsBind _ _ = return Nothing
132140

133141
getTypeLHsExpr :: GHC.TypecheckedModule -> GHC.LHsExpr GHC.Id -> GHC.Ghc (Maybe (GHC.SrcSpan, GHC.Type))
142+
#if __GLASGOW_HASKELL__ >= 708
143+
getTypeLHsExpr _ e = do
144+
#else
134145
getTypeLHsExpr tcm e = do
146+
#endif
135147
hs_env <- GHC.getSession
148+
#if __GLASGOW_HASKELL__ >= 708
149+
(_, mbe) <- liftIO $ Desugar.deSugarExpr hs_env e
150+
#else
151+
let modu = GHC.ms_mod $ GHC.pm_mod_summary $ GHC.tm_parsed_module tcm
152+
rn_env = TcRnTypes.tcg_rdr_env $ fst $ GHC.tm_internals_ tcm
153+
ty_env = TcRnTypes.tcg_type_env $ fst $ GHC.tm_internals_ tcm
136154
(_, mbe) <- liftIO $ Desugar.deSugarExpr hs_env modu rn_env ty_env e
155+
#endif
137156
return ()
138157
case mbe of
139158
Nothing -> return Nothing
140159
Just expr -> return $ Just (GHC.getLoc e, CoreUtils.exprType expr)
141-
where
142-
modu = GHC.ms_mod $ GHC.pm_mod_summary $ GHC.tm_parsed_module tcm
143-
rn_env = TcRnTypes.tcg_rdr_env $ fst $ GHC.tm_internals_ tcm
144-
ty_env = TcRnTypes.tcg_type_env $ fst $ GHC.tm_internals_ tcm
145160

146161
getTypeLPat :: GHC.TypecheckedModule -> GHC.LPat GHC.Id -> GHC.Ghc (Maybe (GHC.SrcSpan, GHC.Type))
147162
getTypeLPat _ (GHC.L spn pat) = return $ Just (spn, TcHsSyn.hsPatType pat)
@@ -161,14 +176,22 @@ pretty dflags =
161176
pretty :: GHC.Type -> String
162177
pretty =
163178
#endif
179+
#if __GLASGOW_HASKELL__ >= 708
180+
Pretty.showDoc Pretty.OneLineMode 0
181+
#else
164182
Pretty.showDocWith Pretty.OneLineMode
183+
#endif
165184
#if __GLASGOW_HASKELL__ >= 706
166185
. Outputable.withPprStyleDoc dflags
167186
#else
168187
. Outputable.withPprStyleDoc
169188
#endif
170189
(Outputable.mkUserStyle Outputable.neverQualify Outputable.AllTheWay)
190+
#if __GLASGOW_HASKELL__ >= 708
191+
. PprTyThing.pprTypeForUser
192+
#else
171193
. PprTyThing.pprTypeForUser False
194+
#endif
172195

173196
------------------------------------------------------------------------------
174197
-- The following was taken from 'ghc-syb-utils'
@@ -188,7 +211,11 @@ everythingStaged stage k z f x
188211
| (const False `extQ` postTcType `extQ` fixity `extQ` nameSet) x = z
189212
| otherwise = foldl k (f x) (gmapQ (everythingStaged stage k z f) x)
190213
where nameSet = const (stage `elem` [Parser,TypeChecker]) :: NameSet.NameSet -> Bool
214+
#if __GLASGOW_HASKELL__ >= 710
215+
postTcType = const (stage<TypeChecker) :: GHC.PostTc GHC.Id GHC.Type -> Bool
216+
#else
191217
postTcType = const (stage<TypeChecker) :: GHC.PostTcType -> Bool
218+
#endif
192219
fixity = const (stage<Renamer) :: GHC.Fixity -> Bool
193220

194221
------------------------------------------------------------------------------
@@ -198,16 +225,25 @@ everythingStaged stage k z f x
198225
infoThing :: String -> GHC.Ghc String
199226
infoThing str = do
200227
names <- GHC.parseName str
228+
#if __GLASGOW_HASKELL__ >= 708
229+
mb_stuffs <- mapM (GHC.getInfo False) names
230+
let filtered = filterOutChildren (\(t,_f,_i,_) -> t) (catMaybes mb_stuffs)
231+
#else
201232
mb_stuffs <- mapM GHC.getInfo names
202233
let filtered = filterOutChildren (\(t,_f,_i) -> t) (catMaybes mb_stuffs)
234+
#endif
203235
unqual <- GHC.getPrintUnqual
204236
#if __GLASGOW_HASKELL__ >= 706
205237
dflags <- DynFlags.getDynFlags
206238
return $ Outputable.showSDocForUser dflags unqual $
207239
#else
208240
return $ Outputable.showSDocForUser unqual $
209241
#endif
242+
#if __GLASGOW_HASKELL__ >= 708
243+
Outputable.vcat (intersperse (Outputable.text "") $ map pprInfo filtered)
244+
#else
210245
Outputable.vcat (intersperse (Outputable.text "") $ map (pprInfo False) filtered)
246+
#endif
211247

212248
-- Filter out names whose parent is also there Good
213249
-- example is '[]', which is both a type and data
@@ -225,13 +261,19 @@ filterOutChildren get_thing xs
225261
Just p -> GHC.getName p `NameSet.elemNameSet` all_names
226262
Nothing -> False
227263

228-
#if __GLASGOW_HASKELL__ >= 706
264+
#if __GLASGOW_HASKELL__ >= 708
265+
pprInfo :: (HscTypes.TyThing, GHC.Fixity, [GHC.ClsInst], [GHC.FamInst]) -> Outputable.SDoc
266+
pprInfo (thing, fixity, insts, _) =
267+
PprTyThing.pprTyThingInContextLoc thing
268+
#elif __GLASGOW_HASKELL__ >= 706
229269
pprInfo :: PprTyThing.PrintExplicitForalls -> (HscTypes.TyThing, GHC.Fixity, [GHC.ClsInst]) -> Outputable.SDoc
270+
pprInfo pefas (thing, fixity, insts) =
271+
PprTyThing.pprTyThingInContextLoc pefas thing
230272
#else
231273
pprInfo :: PprTyThing.PrintExplicitForalls -> (HscTypes.TyThing, GHC.Fixity, [GHC.Instance]) -> Outputable.SDoc
232-
#endif
233274
pprInfo pefas (thing, fixity, insts) =
234275
PprTyThing.pprTyThingInContextLoc pefas thing
276+
#endif
235277
Outputable.$$ show_fixity fixity
236278
Outputable.$$ Outputable.vcat (map GHC.pprInstance insts)
237279
where

0 commit comments

Comments
 (0)