2014-06-28 19:43:51 +00:00
|
|
|
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, CPP, ScopedTypeVariables, RankNTypes #-}
|
2012-02-14 07:09:53 +00:00
|
|
|
|
2013-05-17 01:00:01 +00:00
|
|
|
module Language.Haskell.GhcMod.Gap (
|
|
|
|
Language.Haskell.GhcMod.Gap.ClsInst
|
2012-10-16 10:27:35 +00:00
|
|
|
, mkTarget
|
2013-03-12 13:15:23 +00:00
|
|
|
, withStyle
|
2012-10-16 10:27:35 +00:00
|
|
|
, setLogAction
|
2012-02-14 07:09:53 +00:00
|
|
|
, getSrcSpan
|
|
|
|
, getSrcFile
|
2014-04-27 12:26:03 +00:00
|
|
|
, withContext
|
2012-02-14 07:09:53 +00:00
|
|
|
, fOptions
|
|
|
|
, toStringBuffer
|
2012-10-19 19:19:37 +00:00
|
|
|
, showSeverityCaption
|
2013-07-02 08:48:44 +00:00
|
|
|
, setCabalPkg
|
2014-04-23 01:41:28 +00:00
|
|
|
, setHideAllPackages
|
|
|
|
, addPackageFlags
|
2014-04-26 04:21:22 +00:00
|
|
|
, setDeferTypeErrors
|
2014-06-09 08:30:33 +00:00
|
|
|
, setWarnTypedHoles
|
2014-04-26 04:21:22 +00:00
|
|
|
, setDumpSplices
|
|
|
|
, isDumpSplices
|
2013-07-02 08:48:44 +00:00
|
|
|
, filterOutChildren
|
|
|
|
, infoThing
|
|
|
|
, pprInfo
|
|
|
|
, HasType(..)
|
2013-11-19 03:28:59 +00:00
|
|
|
, errorMsgSpan
|
2013-11-19 03:35:42 +00:00
|
|
|
, typeForUser
|
2014-06-08 10:33:13 +00:00
|
|
|
, nameForUser
|
2014-06-10 19:34:05 +00:00
|
|
|
, occNameForUser
|
2013-11-19 03:54:08 +00:00
|
|
|
, deSugar
|
2014-01-14 06:37:16 +00:00
|
|
|
, showDocWith
|
2014-02-06 12:34:40 +00:00
|
|
|
, GapThing(..)
|
|
|
|
, fromTyThing
|
2014-04-27 12:26:03 +00:00
|
|
|
, fileModSummary
|
2014-04-28 05:36:55 +00:00
|
|
|
, WarnFlags
|
|
|
|
, emptyWarnFlags
|
2014-07-15 03:29:27 +00:00
|
|
|
, benchmarkBuildInfo
|
|
|
|
, benchmarkTargets
|
|
|
|
, toModuleString
|
2014-07-15 03:35:45 +00:00
|
|
|
, GLMatch
|
2014-08-23 12:06:26 +00:00
|
|
|
, GLMatchI
|
2014-07-15 05:44:02 +00:00
|
|
|
, getClass
|
|
|
|
, occName
|
2014-07-18 02:09:11 +00:00
|
|
|
, setFlags
|
2015-01-16 14:47:56 +00:00
|
|
|
, ghcVersion
|
|
|
|
, mkGHCCompilerId
|
|
|
|
, listVisibleModuleNames
|
|
|
|
, listVisibleModules
|
|
|
|
, Language.Haskell.GhcMod.Gap.isSynTyCon
|
2012-02-14 07:09:53 +00:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Control.Applicative hiding (empty)
|
2014-03-27 07:02:16 +00:00
|
|
|
import Control.Monad (filterM)
|
|
|
|
import CoreSyn (CoreExpr)
|
2015-01-16 14:47:56 +00:00
|
|
|
import Data.Version (parseVersion)
|
2014-03-27 07:02:16 +00:00
|
|
|
import Data.List (intersperse)
|
|
|
|
import Data.Maybe (catMaybes)
|
|
|
|
import Data.Time.Clock (UTCTime)
|
2014-02-06 13:09:00 +00:00
|
|
|
import DataCon (dataConRepType)
|
2013-11-19 03:54:08 +00:00
|
|
|
import Desugar (deSugarExpr)
|
2012-02-14 07:09:53 +00:00
|
|
|
import DynFlags
|
2012-10-16 10:27:35 +00:00
|
|
|
import ErrUtils
|
2012-02-14 07:09:53 +00:00
|
|
|
import FastString
|
2014-06-28 19:43:51 +00:00
|
|
|
import GhcMonad
|
2013-07-14 08:07:30 +00:00
|
|
|
import HscTypes
|
2013-05-17 01:00:01 +00:00
|
|
|
import Language.Haskell.GhcMod.GHCChoice
|
2014-05-14 18:55:54 +00:00
|
|
|
import Language.Haskell.GhcMod.Types
|
2013-07-14 08:07:30 +00:00
|
|
|
import NameSet
|
2014-06-08 10:33:13 +00:00
|
|
|
import OccName
|
2012-02-14 07:09:53 +00:00
|
|
|
import Outputable
|
2013-07-14 08:07:30 +00:00
|
|
|
import PprTyThing
|
2012-02-14 07:09:53 +00:00
|
|
|
import StringBuffer
|
2013-07-02 08:48:44 +00:00
|
|
|
import TcType
|
2014-02-06 13:09:00 +00:00
|
|
|
import Var (varType)
|
2015-01-16 14:47:56 +00:00
|
|
|
import Config (cProjectVersion)
|
|
|
|
|
|
|
|
import Text.ParserCombinators.ReadP (readP_to_S)
|
2012-02-14 07:09:53 +00:00
|
|
|
|
2014-07-15 03:29:27 +00:00
|
|
|
import qualified Distribution.PackageDescription as P
|
2012-10-16 10:27:35 +00:00
|
|
|
import qualified InstEnv
|
|
|
|
import qualified Pretty
|
|
|
|
import qualified StringBuffer as SB
|
2014-04-28 05:13:25 +00:00
|
|
|
|
2014-04-28 05:04:18 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
2013-07-02 08:48:44 +00:00
|
|
|
import FamInstEnv
|
2014-02-06 12:40:51 +00:00
|
|
|
import ConLike (ConLike(..))
|
2014-02-06 13:12:07 +00:00
|
|
|
import PatSyn (patSynType)
|
2014-01-08 00:55:06 +00:00
|
|
|
#else
|
|
|
|
import TcRnTypes
|
2013-07-02 09:19:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __GLASGOW_HASKELL__ >= 706
|
|
|
|
import GHC hiding (ClsInst)
|
|
|
|
#else
|
|
|
|
import GHC hiding (Instance)
|
2013-07-02 09:29:08 +00:00
|
|
|
import Control.Arrow hiding ((<+>))
|
2012-10-16 10:27:35 +00:00
|
|
|
import Data.Convertible
|
2014-07-15 05:44:02 +00:00
|
|
|
import RdrName (rdrNameOcc)
|
2012-10-16 10:27:35 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-16 14:47:56 +00:00
|
|
|
import Distribution.Version
|
|
|
|
import Distribution.Simple.Compiler (CompilerId(..), CompilerFlavor(..))
|
|
|
|
#if __GLASGOW_HASKELL__ >= 710
|
|
|
|
import Distribution.Simple.Compiler (CompilerInfo(..), AbiTag(..))
|
|
|
|
import Packages (listVisibleModuleNames, lookupModuleInAllPackages)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __GLASGOW_HASKELL__ < 710
|
|
|
|
import UniqFM (eltsUFM)
|
|
|
|
import Packages (exposedModules, exposed, pkgIdMap)
|
|
|
|
import PackageConfig (PackageConfig, packageConfigId)
|
|
|
|
#endif
|
|
|
|
|
2014-04-28 05:36:55 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 704
|
|
|
|
import qualified Data.IntSet as I (IntSet, empty)
|
2014-07-15 03:29:27 +00:00
|
|
|
import qualified Distribution.ModuleName as M (ModuleName,toFilePath)
|
2014-04-28 05:36:55 +00:00
|
|
|
#endif
|
|
|
|
|
2012-10-16 10:27:35 +00:00
|
|
|
----------------------------------------------------------------
|
|
|
|
----------------------------------------------------------------
|
|
|
|
--
|
|
|
|
#if __GLASGOW_HASKELL__ >= 706
|
|
|
|
type ClsInst = InstEnv.ClsInst
|
|
|
|
#else
|
|
|
|
type ClsInst = InstEnv.Instance
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mkTarget :: TargetId -> Bool -> Maybe (SB.StringBuffer, UTCTime) -> Target
|
|
|
|
#if __GLASGOW_HASKELL__ >= 706
|
|
|
|
mkTarget = Target
|
|
|
|
#else
|
|
|
|
mkTarget tid allowObjCode = Target tid allowObjCode . (fmap . second) convert
|
|
|
|
#endif
|
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
2013-03-12 13:15:23 +00:00
|
|
|
withStyle :: DynFlags -> PprStyle -> SDoc -> Pretty.Doc
|
2012-10-16 10:27:35 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 706
|
2013-03-12 13:15:23 +00:00
|
|
|
withStyle = withPprStyleDoc
|
2012-10-16 10:27:35 +00:00
|
|
|
#else
|
2013-03-12 13:15:23 +00:00
|
|
|
withStyle _ = withPprStyleDoc
|
2012-10-16 10:27:35 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
setLogAction :: DynFlags
|
|
|
|
-> (DynFlags -> Severity -> SrcSpan -> PprStyle -> SDoc -> IO ())
|
|
|
|
-> DynFlags
|
|
|
|
setLogAction df f =
|
|
|
|
#if __GLASGOW_HASKELL__ >= 706
|
|
|
|
df { log_action = f }
|
|
|
|
#else
|
|
|
|
df { log_action = f df }
|
|
|
|
#endif
|
|
|
|
|
2014-01-14 06:37:16 +00:00
|
|
|
showDocWith :: DynFlags -> Pretty.Mode -> Pretty.Doc -> String
|
2014-04-28 05:04:18 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
2014-01-14 06:37:16 +00:00
|
|
|
-- Pretty.showDocWith disappeard.
|
|
|
|
-- https://github.com/ghc/ghc/commit/08a3536e4246e323fbcd8040e0b80001950fe9bc
|
|
|
|
showDocWith dflags mode = Pretty.showDoc mode (pprCols dflags)
|
|
|
|
#else
|
|
|
|
showDocWith _ = Pretty.showDocWith
|
|
|
|
#endif
|
|
|
|
|
2012-02-14 07:09:53 +00:00
|
|
|
----------------------------------------------------------------
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
getSrcSpan :: SrcSpan -> Maybe (Int,Int,Int,Int)
|
|
|
|
#if __GLASGOW_HASKELL__ >= 702
|
|
|
|
getSrcSpan (RealSrcSpan spn)
|
|
|
|
#else
|
|
|
|
getSrcSpan spn | isGoodSrcSpan spn
|
|
|
|
#endif
|
|
|
|
= Just (srcSpanStartLine spn
|
|
|
|
, srcSpanStartCol spn
|
|
|
|
, srcSpanEndLine spn
|
|
|
|
, srcSpanEndCol spn)
|
|
|
|
getSrcSpan _ = Nothing
|
|
|
|
|
|
|
|
getSrcFile :: SrcSpan -> Maybe String
|
|
|
|
#if __GLASGOW_HASKELL__ >= 702
|
|
|
|
getSrcFile (RealSrcSpan spn) = Just . unpackFS . srcSpanFile $ spn
|
|
|
|
#else
|
|
|
|
getSrcFile spn | isGoodSrcSpan spn = Just . unpackFS . srcSpanFile $ spn
|
|
|
|
#endif
|
|
|
|
getSrcFile _ = Nothing
|
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
2014-06-28 19:43:51 +00:00
|
|
|
toStringBuffer :: GhcMonad m => [String] -> m StringBuffer
|
2012-02-14 07:09:53 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 702
|
|
|
|
toStringBuffer = return . stringToStringBuffer . unlines
|
|
|
|
#else
|
|
|
|
toStringBuffer = liftIO . stringToStringBuffer . unlines
|
|
|
|
#endif
|
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
fOptions :: [String]
|
2015-01-16 14:47:56 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 710
|
|
|
|
fOptions = [option | (FlagSpec option _ _ _) <- fFlags]
|
|
|
|
++ [option | (FlagSpec option _ _ _) <- fWarningFlags]
|
|
|
|
++ [option | (FlagSpec option _ _ _) <- fLangFlags]
|
|
|
|
#elif __GLASGOW_HASKELL__ >= 704
|
2012-06-07 06:56:55 +00:00
|
|
|
fOptions = [option | (option,_,_) <- fFlags]
|
|
|
|
++ [option | (option,_,_) <- fWarningFlags]
|
|
|
|
++ [option | (option,_,_) <- fLangFlags]
|
2014-04-28 05:13:25 +00:00
|
|
|
#else
|
2012-02-14 07:09:53 +00:00
|
|
|
fOptions = [option | (option,_,_,_) <- fFlags]
|
2014-01-14 06:25:06 +00:00
|
|
|
++ [option | (option,_,_,_) <- fWarningFlags]
|
|
|
|
++ [option | (option,_,_,_) <- fLangFlags]
|
2012-02-14 07:09:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
2014-06-28 19:43:51 +00:00
|
|
|
fileModSummary :: GhcMonad m => FilePath -> m ModSummary
|
2014-04-27 12:26:03 +00:00
|
|
|
fileModSummary file = do
|
|
|
|
mss <- getModuleGraph
|
|
|
|
let [ms] = filter (\m -> ml_hs_file (ms_location m) == Just file) mss
|
|
|
|
return ms
|
|
|
|
|
2014-06-28 19:43:51 +00:00
|
|
|
withContext :: GhcMonad m => m a -> m a
|
2014-04-27 12:26:03 +00:00
|
|
|
withContext action = gbracket setup teardown body
|
|
|
|
where
|
|
|
|
setup = getContext
|
2014-04-28 00:28:57 +00:00
|
|
|
teardown = setCtx
|
2014-04-27 12:26:03 +00:00
|
|
|
body _ = do
|
2014-04-28 00:00:03 +00:00
|
|
|
topImports >>= setCtx
|
2014-04-27 12:26:03 +00:00
|
|
|
action
|
2014-04-27 13:48:24 +00:00
|
|
|
topImports = do
|
|
|
|
mss <- getModuleGraph
|
2014-04-28 02:26:06 +00:00
|
|
|
ms <- map modName <$> filterM isTop mss
|
|
|
|
#if __GLASGOW_HASKELL__ >= 704
|
|
|
|
return ms
|
|
|
|
#else
|
|
|
|
return (ms,[])
|
|
|
|
#endif
|
2014-04-28 00:00:03 +00:00
|
|
|
isTop mos = lookupMod mos ||> returnFalse
|
|
|
|
lookupMod mos = lookupModule (ms_mod_name mos) Nothing >> return True
|
|
|
|
returnFalse = return False
|
2012-10-16 10:27:35 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 706
|
2014-04-28 00:00:03 +00:00
|
|
|
modName = IIModule . moduleName . ms_mod
|
|
|
|
setCtx = setContext
|
2014-04-27 12:26:03 +00:00
|
|
|
#elif __GLASGOW_HASKELL__ >= 704
|
2014-04-28 00:00:03 +00:00
|
|
|
modName = IIModule . ms_mod
|
|
|
|
setCtx = setContext
|
2012-02-14 07:09:53 +00:00
|
|
|
#else
|
2014-04-28 00:00:03 +00:00
|
|
|
modName = ms_mod
|
2014-04-28 02:26:06 +00:00
|
|
|
setCtx = uncurry setContext
|
2012-02-14 07:09:53 +00:00
|
|
|
#endif
|
2012-02-15 06:57:43 +00:00
|
|
|
|
2012-10-19 19:19:37 +00:00
|
|
|
showSeverityCaption :: Severity -> String
|
|
|
|
#if __GLASGOW_HASKELL__ >= 706
|
2013-02-13 07:04:22 +00:00
|
|
|
showSeverityCaption SevWarning = "Warning: "
|
2012-10-19 19:19:37 +00:00
|
|
|
showSeverityCaption _ = ""
|
|
|
|
#else
|
|
|
|
showSeverityCaption = const ""
|
|
|
|
#endif
|
2013-07-02 08:48:44 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
setCabalPkg :: DynFlags -> DynFlags
|
2014-04-28 05:04:18 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
2013-07-02 08:48:44 +00:00
|
|
|
setCabalPkg dflag = gopt_set dflag Opt_BuildingCabalPackage
|
|
|
|
#else
|
|
|
|
setCabalPkg dflag = dopt_set dflag Opt_BuildingCabalPackage
|
|
|
|
#endif
|
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
2014-04-23 01:41:28 +00:00
|
|
|
setHideAllPackages :: DynFlags -> DynFlags
|
2014-04-28 05:04:18 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
2014-04-26 04:21:22 +00:00
|
|
|
setHideAllPackages df = gopt_set df Opt_HideAllPackages
|
2013-07-14 08:07:30 +00:00
|
|
|
#else
|
2014-04-26 04:21:22 +00:00
|
|
|
setHideAllPackages df = dopt_set df Opt_HideAllPackages
|
2013-07-14 08:07:30 +00:00
|
|
|
#endif
|
2014-04-23 01:41:28 +00:00
|
|
|
|
|
|
|
addPackageFlags :: [Package] -> DynFlags -> DynFlags
|
|
|
|
addPackageFlags pkgs df =
|
|
|
|
df { packageFlags = packageFlags df ++ expose `map` pkgs }
|
|
|
|
where
|
2015-01-16 14:47:56 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 710
|
|
|
|
expose :: Package -> PackageFlag
|
|
|
|
expose pkg = ExposePackage (PackageIdArg $ showPkgId pkg) (ModRenaming True [])
|
|
|
|
#else
|
2014-04-17 21:40:11 +00:00
|
|
|
expose pkg = ExposePackageId $ showPkgId pkg
|
2015-01-16 14:47:56 +00:00
|
|
|
#endif
|
2013-07-02 08:48:44 +00:00
|
|
|
|
2014-04-26 04:21:22 +00:00
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
setDumpSplices :: DynFlags -> DynFlags
|
|
|
|
setDumpSplices dflag = dopt_set dflag Opt_D_dump_splices
|
|
|
|
|
|
|
|
isDumpSplices :: DynFlags -> Bool
|
|
|
|
isDumpSplices dflag = dopt Opt_D_dump_splices dflag
|
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
setDeferTypeErrors :: DynFlags -> DynFlags
|
2014-04-28 05:04:18 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
2014-04-26 04:21:22 +00:00
|
|
|
setDeferTypeErrors dflag = gopt_set dflag Opt_DeferTypeErrors
|
|
|
|
#elif __GLASGOW_HASKELL__ >= 706
|
|
|
|
setDeferTypeErrors dflag = dopt_set dflag Opt_DeferTypeErrors
|
|
|
|
#else
|
|
|
|
setDeferTypeErrors = id
|
|
|
|
#endif
|
|
|
|
|
2014-06-09 08:30:33 +00:00
|
|
|
setWarnTypedHoles :: DynFlags -> DynFlags
|
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
|
|
|
setWarnTypedHoles dflag = wopt_set dflag Opt_WarnTypedHoles
|
|
|
|
#else
|
|
|
|
setWarnTypedHoles = id
|
2014-04-26 04:21:22 +00:00
|
|
|
#endif
|
|
|
|
|
2013-07-02 08:48:44 +00:00
|
|
|
----------------------------------------------------------------
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
class HasType a where
|
|
|
|
getType :: GhcMonad m => TypecheckedModule -> a -> m (Maybe (SrcSpan, Type))
|
|
|
|
|
|
|
|
|
|
|
|
instance HasType (LHsBind Id) where
|
2014-04-28 05:04:18 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
2014-07-11 05:12:36 +00:00
|
|
|
getType _ (L spn FunBind{fun_matches = m}) = return $ Just (spn, typ)
|
|
|
|
where in_tys = mg_arg_tys m
|
|
|
|
out_typ = mg_res_ty m
|
|
|
|
typ = mkFunTys in_tys out_typ
|
2013-07-14 08:07:30 +00:00
|
|
|
#else
|
2013-07-02 08:48:44 +00:00
|
|
|
getType _ (L spn FunBind{fun_matches = MatchGroup _ typ}) = return $ Just (spn, typ)
|
2013-07-14 08:07:30 +00:00
|
|
|
#endif
|
2013-07-02 08:48:44 +00:00
|
|
|
getType _ _ = return Nothing
|
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
----------------------------------------------------------------
|
|
|
|
-- from ghc/InteractiveUI.hs
|
|
|
|
|
|
|
|
filterOutChildren :: (a -> TyThing) -> [a] -> [a]
|
|
|
|
filterOutChildren get_thing xs
|
|
|
|
= [x | x <- xs, not (getName (get_thing x) `elemNameSet` implicits)]
|
|
|
|
where
|
|
|
|
implicits = mkNameSet [getName t | x <- xs, t <- implicitTyThings (get_thing x)]
|
|
|
|
|
2014-06-28 19:43:51 +00:00
|
|
|
infoThing :: GhcMonad m => String -> m SDoc
|
2013-07-02 08:48:44 +00:00
|
|
|
infoThing str = do
|
|
|
|
names <- parseName str
|
2014-04-28 05:04:18 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
2013-07-02 08:48:44 +00:00
|
|
|
mb_stuffs <- mapM (getInfo False) names
|
|
|
|
let filtered = filterOutChildren (\(t,_f,_i,_fam) -> t) (catMaybes mb_stuffs)
|
2013-07-14 08:07:30 +00:00
|
|
|
#else
|
2013-07-02 08:48:44 +00:00
|
|
|
mb_stuffs <- mapM getInfo names
|
|
|
|
let filtered = filterOutChildren (\(t,_f,_i) -> t) (catMaybes mb_stuffs)
|
|
|
|
#endif
|
2013-07-14 08:07:30 +00:00
|
|
|
return $ vcat (intersperse (text "") $ map (pprInfo False) filtered)
|
2013-07-02 08:48:44 +00:00
|
|
|
|
2014-04-28 05:04:18 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
2013-11-12 23:44:34 +00:00
|
|
|
pprInfo :: Bool -> (TyThing, GHC.Fixity, [ClsInst], [FamInst]) -> SDoc
|
|
|
|
pprInfo _ (thing, fixity, insts, famInsts)
|
|
|
|
= pprTyThingInContextLoc thing
|
2013-07-02 08:48:44 +00:00
|
|
|
$$ show_fixity fixity
|
|
|
|
$$ InstEnv.pprInstances insts
|
|
|
|
$$ pprFamInsts famInsts
|
|
|
|
where
|
|
|
|
show_fixity fx
|
|
|
|
| fx == defaultFixity = Outputable.empty
|
|
|
|
| otherwise = ppr fx <+> ppr (getName thing)
|
2013-07-14 08:07:30 +00:00
|
|
|
#else
|
2013-07-02 08:48:44 +00:00
|
|
|
pprInfo :: PrintExplicitForalls -> (TyThing, GHC.Fixity, [ClsInst]) -> SDoc
|
|
|
|
pprInfo pefas (thing, fixity, insts)
|
|
|
|
= pprTyThingInContextLoc pefas thing
|
|
|
|
$$ show_fixity fixity
|
|
|
|
$$ vcat (map pprInstance insts)
|
|
|
|
where
|
|
|
|
show_fixity fx
|
|
|
|
| fx == defaultFixity = Outputable.empty
|
|
|
|
| otherwise = ppr fx <+> ppr (getName thing)
|
|
|
|
#endif
|
2013-11-12 23:44:34 +00:00
|
|
|
|
2013-11-19 03:28:59 +00:00
|
|
|
----------------------------------------------------------------
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
errorMsgSpan :: ErrMsg -> SrcSpan
|
2014-04-28 05:04:18 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
2013-11-19 03:28:59 +00:00
|
|
|
errorMsgSpan = errMsgSpan
|
|
|
|
#else
|
|
|
|
errorMsgSpan = head . errMsgSpans
|
|
|
|
#endif
|
2013-11-19 03:35:42 +00:00
|
|
|
|
|
|
|
typeForUser :: Type -> SDoc
|
2014-04-28 05:04:18 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
2013-11-19 03:35:42 +00:00
|
|
|
typeForUser = pprTypeForUser
|
|
|
|
#else
|
|
|
|
typeForUser = pprTypeForUser False
|
|
|
|
#endif
|
2013-11-19 03:54:08 +00:00
|
|
|
|
2014-06-08 10:33:13 +00:00
|
|
|
nameForUser :: Name -> SDoc
|
|
|
|
nameForUser = pprOccName . getOccName
|
|
|
|
|
2014-06-10 19:34:05 +00:00
|
|
|
occNameForUser :: OccName -> SDoc
|
|
|
|
occNameForUser = pprOccName
|
|
|
|
|
2013-11-19 03:54:08 +00:00
|
|
|
deSugar :: TypecheckedModule -> LHsExpr Id -> HscEnv
|
2014-03-27 07:02:16 +00:00
|
|
|
-> IO (Maybe CoreExpr)
|
2014-04-28 05:04:18 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
2014-01-08 00:55:06 +00:00
|
|
|
deSugar _ e hs_env = snd <$> deSugarExpr hs_env e
|
2013-11-19 03:54:08 +00:00
|
|
|
#else
|
|
|
|
deSugar tcm e hs_env = snd <$> deSugarExpr hs_env modu rn_env ty_env e
|
|
|
|
where
|
|
|
|
modu = ms_mod $ pm_mod_summary $ tm_parsed_module tcm
|
|
|
|
tcgEnv = fst $ tm_internals_ tcm
|
|
|
|
rn_env = tcg_rdr_env tcgEnv
|
|
|
|
ty_env = tcg_type_env tcgEnv
|
|
|
|
#endif
|
2014-02-06 12:34:40 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
2014-02-06 13:09:00 +00:00
|
|
|
data GapThing = GtA Type | GtT TyCon | GtN
|
2014-02-06 12:34:40 +00:00
|
|
|
|
|
|
|
fromTyThing :: TyThing -> GapThing
|
2014-02-06 13:09:00 +00:00
|
|
|
fromTyThing (AnId i) = GtA $ varType i
|
2014-04-28 05:04:18 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
2014-02-06 13:09:00 +00:00
|
|
|
fromTyThing (AConLike (RealDataCon d)) = GtA $ dataConRepType d
|
|
|
|
fromTyThing (AConLike (PatSynCon p)) = GtA $ patSynType p
|
2014-02-06 12:40:51 +00:00
|
|
|
#else
|
2014-02-06 13:09:00 +00:00
|
|
|
fromTyThing (ADataCon d) = GtA $ dataConRepType d
|
2014-02-06 12:40:51 +00:00
|
|
|
#endif
|
|
|
|
fromTyThing (ATyCon t) = GtT t
|
|
|
|
fromTyThing _ = GtN
|
2014-04-28 05:36:55 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
#if __GLASGOW_HASKELL__ >= 704
|
|
|
|
type WarnFlags = I.IntSet
|
|
|
|
emptyWarnFlags :: WarnFlags
|
|
|
|
emptyWarnFlags = I.empty
|
|
|
|
#else
|
|
|
|
type WarnFlags = [WarningFlag]
|
|
|
|
emptyWarnFlags :: WarnFlags
|
|
|
|
emptyWarnFlags = []
|
|
|
|
#endif
|
2014-07-15 03:29:27 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
benchmarkBuildInfo :: P.PackageDescription -> [P.BuildInfo]
|
|
|
|
#if __GLASGOW_HASKELL__ >= 704
|
|
|
|
benchmarkBuildInfo pd = map P.benchmarkBuildInfo $ P.benchmarks pd
|
|
|
|
#else
|
|
|
|
benchmarkBuildInfo pd = []
|
|
|
|
#endif
|
|
|
|
|
|
|
|
benchmarkTargets :: P.PackageDescription -> [String]
|
|
|
|
#if __GLASGOW_HASKELL__ >= 704
|
|
|
|
benchmarkTargets pd = map toModuleString $ concatMap P.benchmarkModules $ P.benchmarks pd
|
|
|
|
#else
|
|
|
|
benchmarkTargets = []
|
|
|
|
#endif
|
|
|
|
|
|
|
|
toModuleString :: M.ModuleName -> String
|
|
|
|
toModuleString mn = fromFilePath $ M.toFilePath mn
|
|
|
|
where
|
|
|
|
fromFilePath :: FilePath -> String
|
|
|
|
fromFilePath fp = map (\c -> if c=='/' then '.' else c) fp
|
2014-07-15 03:35:45 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
|
|
|
type GLMatch = LMatch RdrName (LHsExpr RdrName)
|
2014-08-23 12:06:26 +00:00
|
|
|
type GLMatchI = LMatch Id (LHsExpr Id)
|
2014-07-15 03:35:45 +00:00
|
|
|
#else
|
|
|
|
type GLMatch = LMatch RdrName
|
2014-08-23 12:06:26 +00:00
|
|
|
type GLMatchI = LMatch Id
|
2014-07-15 03:35:45 +00:00
|
|
|
#endif
|
2014-07-15 05:44:02 +00:00
|
|
|
|
|
|
|
getClass :: [LInstDecl Name] -> Maybe (Name, SrcSpan)
|
2015-01-16 14:47:56 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 710
|
|
|
|
-- Instance declarations of sort 'instance F (G a)'
|
|
|
|
getClass [L loc (ClsInstD (ClsInstDecl {cid_poly_ty = (L _ (HsForAllTy _ _ _ _ (L _ (HsAppTy (L _ (HsTyVar className)) _))))}))] = Just (className, loc)
|
|
|
|
-- Instance declarations of sort 'instance F G' (no variables)
|
|
|
|
getClass [L loc (ClsInstD (ClsInstDecl {cid_poly_ty = (L _ (HsAppTy (L _ (HsTyVar className)) _))}))] = Just (className, loc)
|
|
|
|
#elif __GLASGOW_HASKELL__ >= 708
|
2014-07-15 05:44:02 +00:00
|
|
|
-- Instance declarations of sort 'instance F (G a)'
|
|
|
|
getClass [L loc (ClsInstD (ClsInstDecl {cid_poly_ty = (L _ (HsForAllTy _ _ _ (L _ (HsAppTy (L _ (HsTyVar className)) _))))}))] = Just (className, loc)
|
|
|
|
-- Instance declarations of sort 'instance F G' (no variables)
|
|
|
|
getClass [L loc (ClsInstD (ClsInstDecl {cid_poly_ty = (L _ (HsAppTy (L _ (HsTyVar className)) _))}))] = Just (className, loc)
|
|
|
|
#elif __GLASGOW_HASKELL__ >= 706
|
|
|
|
getClass [L loc (ClsInstD (L _ (HsForAllTy _ _ _ (L _ (HsAppTy (L _ (HsTyVar className)) _)))) _ _ _)] = Just (className, loc)
|
|
|
|
getClass[L loc (ClsInstD (L _ (HsAppTy (L _ (HsTyVar className)) _)) _ _ _)] = Just (className, loc)
|
|
|
|
#else
|
|
|
|
getClass [L loc (InstDecl (L _ (HsForAllTy _ _ _ (L _ (HsAppTy (L _ (HsTyVar className)) _)))) _ _ _)] = Just (className, loc)
|
|
|
|
getClass [L loc (InstDecl (L _ (HsAppTy (L _ (HsTyVar className)) _)) _ _ _)] = Just (className, loc)
|
|
|
|
#endif
|
|
|
|
getClass _ = Nothing
|
|
|
|
|
|
|
|
#if __GLASGOW_HASKELL__ < 706
|
2014-07-15 06:13:06 +00:00
|
|
|
occName :: RdrName -> OccName
|
2014-07-15 05:44:02 +00:00
|
|
|
occName = rdrNameOcc
|
|
|
|
#endif
|
2014-07-18 02:09:11 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
setFlags :: DynFlags -> DynFlags
|
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
|
|
|
setFlags df = df `gopt_unset` Opt_SpecConstr -- consume memory if -O2
|
|
|
|
#else
|
|
|
|
setFlags = id
|
|
|
|
#endif
|
2015-01-16 14:47:56 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
ghcVersion :: Version
|
|
|
|
ghcVersion =
|
|
|
|
case readP_to_S parseVersion $ cProjectVersion of
|
|
|
|
[(ver, "")] -> ver
|
|
|
|
_ -> error "parsing ghc version(cProjectVersion) failed."
|
|
|
|
|
|
|
|
|
|
|
|
#if __GLASGOW_HASKELL__ >= 710
|
|
|
|
mkGHCCompilerId :: Version -> Distribution.Simple.Compiler.CompilerInfo
|
|
|
|
-- TODO we should probably fill this out properly
|
|
|
|
mkGHCCompilerId v =
|
|
|
|
CompilerInfo (CompilerId GHC v) NoAbiTag Nothing Nothing Nothing
|
|
|
|
#else
|
|
|
|
mkGHCCompilerId :: Version -> CompilerId
|
|
|
|
mkGHCCompilerId v = CompilerId GHC v
|
|
|
|
#endif
|
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
#if __GLASGOW_HASKELL__ < 710
|
|
|
|
-- Copied from ghc/InteractiveUI.hs
|
|
|
|
allExposedPackageConfigs :: DynFlags -> [PackageConfig]
|
|
|
|
allExposedPackageConfigs df = filter exposed $ eltsUFM $ pkgIdMap $ pkgState df
|
|
|
|
|
|
|
|
allExposedModules :: DynFlags -> [ModuleName]
|
|
|
|
allExposedModules df = concat $ map exposedModules $ allExposedPackageConfigs df
|
|
|
|
|
|
|
|
listVisibleModuleNames :: DynFlags -> [ModuleName]
|
|
|
|
listVisibleModuleNames = allExposedModules
|
|
|
|
#endif
|
|
|
|
|
|
|
|
listVisibleModules :: DynFlags -> [GHC.Module]
|
|
|
|
listVisibleModules df = let
|
|
|
|
#if __GLASGOW_HASKELL__ >= 710
|
|
|
|
modNames = listVisibleModuleNames df
|
|
|
|
mods = [ m | mn <- modNames, (m, _) <- lookupModuleInAllPackages df mn ]
|
|
|
|
#else
|
|
|
|
pkgCfgs = allExposedPackageConfigs df
|
|
|
|
mods = [ mkModule pid modname | p <- pkgCfgs
|
|
|
|
, let pid = packageConfigId p
|
|
|
|
, modname <- exposedModules p ]
|
|
|
|
#endif
|
|
|
|
in mods
|
|
|
|
|
|
|
|
isSynTyCon :: TyCon -> Bool
|
|
|
|
#if __GLASGOW_HASKELL__ >= 710
|
|
|
|
isSynTyCon = GHC.isTypeSynonymTyCon
|
|
|
|
#else
|
|
|
|
isSynTyCon = GHC.isSynTyCon
|
|
|
|
#endif
|