diff options
author | Bodigrim <andrew.lelechenko@gmail.com> | 2022-12-18 02:27:47 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-12-20 21:16:37 -0500 |
commit | 5d96fd5060958238d5b5c98f14a8b9221c87df93 (patch) | |
tree | b7aaf8832158d93dc82d0125ce770cbefb0fa39a /compiler/GHC | |
parent | 666d0ba72b946721a900ff3e803d4b73879c8fbf (diff) | |
download | haskell-5d96fd5060958238d5b5c98f14a8b9221c87df93.tar.gz |
Make GHC.Driver.Main.hscTcRnLookupRdrName to return NonEmpty
Diffstat (limited to 'compiler/GHC')
-rw-r--r-- | compiler/GHC/Driver/Main.hs | 9 | ||||
-rw-r--r-- | compiler/GHC/Runtime/Debugger.hs | 3 | ||||
-rw-r--r-- | compiler/GHC/Runtime/Eval.hs | 3 |
3 files changed, 11 insertions, 4 deletions
diff --git a/compiler/GHC/Driver/Main.hs b/compiler/GHC/Driver/Main.hs index b6ff27621b..976cf12b55 100644 --- a/compiler/GHC/Driver/Main.hs +++ b/compiler/GHC/Driver/Main.hs @@ -266,6 +266,7 @@ import GHC.SysTools.BaseDir (findTopDir) import Data.Data hiding (Fixity, TyCon) import Data.List ( nub, isPrefixOf, partition ) +import qualified Data.List.NonEmpty as NE import Control.Monad import Data.IORef import System.FilePath as FilePath @@ -445,11 +446,15 @@ ioMsgMaybe' ioA = do -- ----------------------------------------------------------------------------- -- | Lookup things in the compiler's environment -hscTcRnLookupRdrName :: HscEnv -> LocatedN RdrName -> IO [Name] +hscTcRnLookupRdrName :: HscEnv -> LocatedN RdrName -> IO (NonEmpty Name) hscTcRnLookupRdrName hsc_env0 rdr_name = runInteractiveHsc hsc_env0 $ do { hsc_env <- getHscEnv - ; ioMsgMaybe $ hoistTcRnMessage $ tcRnLookupRdrName hsc_env rdr_name } + -- tcRnLookupRdrName can return empty list only together with TcRnUnknownMessage. + -- Once errors has been dealt with in hoistTcRnMessage, we can enforce + -- this invariant in types by converting to NonEmpty. + ; ioMsgMaybe $ fmap (fmap (>>= NE.nonEmpty)) $ hoistTcRnMessage $ + tcRnLookupRdrName hsc_env rdr_name } hscTcRcLookupName :: HscEnv -> Name -> IO (Maybe TyThing) hscTcRcLookupName hsc_env0 name = runInteractiveHsc hsc_env0 $ do diff --git a/compiler/GHC/Runtime/Debugger.hs b/compiler/GHC/Runtime/Debugger.hs index a89227aada..7448f62234 100644 --- a/compiler/GHC/Runtime/Debugger.hs +++ b/compiler/GHC/Runtime/Debugger.hs @@ -49,6 +49,7 @@ import GHC.Types.TyThing import Control.Monad import Control.Monad.Catch as MC import Data.List ( (\\), partition ) +import qualified Data.List.NonEmpty as NE import Data.Maybe import Data.IORef @@ -57,7 +58,7 @@ import Data.IORef ------------------------------------- pprintClosureCommand :: GhcMonad m => Bool -> Bool -> String -> m () pprintClosureCommand bindThings force str = do - tythings <- (catMaybes . concat) `liftM` + tythings <- (catMaybes . concatMap NE.toList) `liftM` mapM (\w -> GHC.parseName w >>= mapM GHC.lookupName) (words str) diff --git a/compiler/GHC/Runtime/Eval.hs b/compiler/GHC/Runtime/Eval.hs index 0b62544433..74eba30421 100644 --- a/compiler/GHC/Runtime/Eval.hs +++ b/compiler/GHC/Runtime/Eval.hs @@ -121,6 +121,7 @@ import Data.Either import Data.IntMap (IntMap) import qualified Data.IntMap as IntMap import Data.List (find,intercalate) +import Data.List.NonEmpty (NonEmpty) import Control.Monad import Control.Monad.Catch as MC import Data.Array @@ -903,7 +904,7 @@ getRdrNamesInScope = withSession $ \hsc_env -> do -- | Parses a string as an identifier, and returns the list of 'Name's that -- the identifier can refer to in the current interactive context. -parseName :: GhcMonad m => String -> m [Name] +parseName :: GhcMonad m => String -> m (NonEmpty Name) parseName str = withSession $ \hsc_env -> liftIO $ do { lrdr_name <- hscParseIdentifier hsc_env str ; hscTcRnLookupRdrName hsc_env lrdr_name } |