Skip to content

Commit

Permalink
Prune modules, reduce qualification
Browse files Browse the repository at this point in the history
  • Loading branch information
shayne-fletcher committed May 3, 2020
1 parent e757a2c commit b649373
Show file tree
Hide file tree
Showing 26 changed files with 117 additions and 133 deletions.
1 change: 0 additions & 1 deletion hlint.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ library
GHC.Util.HsDecl
GHC.Util.HsExpr
GHC.Util.Module
GHC.Util.Outputable
GHC.Util.SrcLoc
GHC.Util.DynFlags
GHC.Util.RdrName
Expand Down
1 change: 1 addition & 0 deletions src/Config/Compute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Name
import Bag
import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances
import Language.Haskell.GhclibParserEx.GHC.Hs.Expr
import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable
import SrcLoc
import Prelude

Expand Down
7 changes: 4 additions & 3 deletions src/Config/Haskell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Prelude

import GHC.Util

import SrcLoc as GHC
import SrcLoc
import GHC.Hs.Extension
import GHC.Hs.Decls hiding (SpliceDecl)
import GHC.Hs.Expr hiding (Match)
Expand All @@ -25,6 +25,7 @@ import ApiAnnotation
import OccName
import Outputable

import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable

-- | Read an {-# ANN #-} pragma and determine if it is intended for HLint.
-- Return Nothing if it is not an HLint pragma, otherwise what it means.
Expand All @@ -46,7 +47,7 @@ readPragma (HsAnnotation _ _ provenance expr) = f expr
f _ = Nothing
readPragma _ = Nothing

readComment :: GHC.Located AnnotationComment -> [Classify]
readComment :: Located AnnotationComment -> [Classify]
readComment c@(L pos AnnBlockComment{})
| (hash, x) <- maybe (False, x) (True,) $ stripPrefix "#" x
, x <- trim x
Expand Down Expand Up @@ -79,7 +80,7 @@ errorOn (L pos val) msg = exitMessageImpure $
": Error while reading hint file, " ++ msg ++ "\n" ++
unsafePrettyPrint val

errorOnComment :: GHC.Located AnnotationComment -> String -> b
errorOnComment :: Located AnnotationComment -> String -> b
errorOnComment c@(L s _) msg = exitMessageImpure $
let isMultiline = isCommentMultiline c in
showSrcSpan' s ++
Expand Down
26 changes: 13 additions & 13 deletions src/Config/Yaml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ import Timing
import Prelude

import Bag
import qualified Lexer as GHC
import qualified ErrUtils
import qualified Outputable
import Lexer
import ErrUtils hiding (Severity)
import Outputable
import GHC.Hs
import SrcLoc
import qualified RdrName as GHC
import qualified OccName as GHC
import RdrName
import OccName
import GHC.Util (baseDynFlags, Scope,scopeCreate)
import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances
import Data.Char
Expand Down Expand Up @@ -161,13 +161,13 @@ allowFields v allow = do
when (bad /= []) $
parseFail v $ "Not allowed keys: " ++ unwords bad

parseGHC :: (ParseFlags -> String -> GHC.ParseResult v) -> Val -> Parser v
parseGHC :: (ParseFlags -> String -> ParseResult v) -> Val -> Parser v
parseGHC parser v = do
x <- parseString v
case parser defaultParseFlags{extensions=configExtensions} x of
GHC.POk _ x -> pure x
GHC.PFailed ps ->
let (_, errs) = GHC.getMessages ps baseDynFlags
case parser defaultParseFlags{enabledExtensions=configExtensions} x of
POk _ x -> pure x
PFailed ps ->
let (_, errs) = getMessages ps baseDynFlags
errMsg = head (bagToList errs)
msg = Outputable.showSDoc baseDynFlags $ ErrUtils.pprLocErrMsg errMsg
in parseFail v $ "Failed to parse " ++ msg ++ ", when parsing:\n " ++ x
Expand Down Expand Up @@ -277,8 +277,8 @@ parseWithin :: Val -> Parser [(String, String)] -- (module, decl)
parseWithin v = do
x <- parseGHC parseExpGhcWithMode v
case x of
L _ (HsVar _ (L _ (GHC.Unqual x))) -> pure $ f "" (GHC.occNameString x)
L _ (HsVar _ (L _ (GHC.Qual mod x))) -> pure $ f (moduleNameString mod) (GHC.occNameString x)
L _ (HsVar _ (L _ (Unqual x))) -> pure $ f "" (occNameString x)
L _ (HsVar _ (L _ (Qual mod x))) -> pure $ f (moduleNameString mod) (occNameString x)
_ -> parseFail v "Bad classification rule"
where
f mod name@(c:_) | isUpper c = [(mod,name),(mod ++ ['.' | mod /= ""] ++ name, "")]
Expand All @@ -300,7 +300,7 @@ guessName lhs rhs
where
(ls, rs) = both f (lhs, rhs)
f :: LHsExpr GhcPs -> [String]
f x = [y | L _ (HsVar _ (L _ x)) <- universe x, let y = GHC.occNameString $ GHC.rdrNameOcc x, not $ isUnifyVar y, y /= "."]
f x = [y | L _ (HsVar _ (L _ x)) <- universe x, let y = occNameString $ rdrNameOcc x, not $ isUnifyVar y, y /= "."]


asNote :: String -> Note
Expand Down
23 changes: 6 additions & 17 deletions src/GHC/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ module GHC.Util (
, module GHC.Util.HsDecl
, module GHC.Util.HsExpr
, module GHC.Util.Module
, module GHC.Util.Outputable
, module GHC.Util.SrcLoc
, module GHC.Util.DynFlags
, module GHC.Util.Scope
, module GHC.Util.RdrName
, module GHC.Util.Unify

, parsePragmasIntoDynFlags
, parseFileGhcLib, parseExpGhcLib, parseImportGhcLib, parseDeclGhcLib
, fileToModule
, pattern SrcSpan, srcSpanFilename, srcSpanStartLine', srcSpanStartColumn, srcSpanEndLine', srcSpanEndColumn
, pattern SrcLoc, srcFilename, srcLine, srcColumn
, showSrcSpan',
Expand All @@ -28,15 +26,15 @@ import GHC.Util.ApiAnnotation
import GHC.Util.HsExpr
import GHC.Util.HsDecl
import GHC.Util.Module
import GHC.Util.Outputable
import GHC.Util.SrcLoc
import GHC.Util.DynFlags
import GHC.Util.RdrName
import GHC.Util.Scope
import GHC.Util.Unify

import qualified Language.Haskell.GhclibParserEx.GHC.Parser as GhclibParserEx
import Language.Haskell.GhclibParserEx.GHC.Parser (parseFile)
import Language.Haskell.GhclibParserEx.GHC.Driver.Session (parsePragmasIntoDynFlags)
import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable

import GHC.Hs
import Lexer
Expand All @@ -47,18 +45,9 @@ import FastString
import System.FilePath
import Language.Preprocessor.Unlit

parseExpGhcLib :: String -> DynFlags -> ParseResult (LHsExpr GhcPs)
parseExpGhcLib = GhclibParserEx.parseExpression

parseImportGhcLib :: String -> DynFlags -> ParseResult (LImportDecl GhcPs)
parseImportGhcLib = GhclibParserEx.parseImport

parseDeclGhcLib :: String -> DynFlags -> ParseResult (LHsDecl GhcPs)
parseDeclGhcLib = GhclibParserEx.parseDeclaration

parseFileGhcLib :: FilePath -> String -> DynFlags -> ParseResult (Located (HsModule GhcPs))
parseFileGhcLib filename str flags =
GhclibParserEx.parseFile filename flags
fileToModule :: FilePath -> String -> DynFlags -> ParseResult (Located (HsModule GhcPs))
fileToModule filename str flags =
parseFile filename flags
(if takeExtension filename /= ".lhs" then str else unlit filename str)

{-# COMPLETE SrcSpan #-}
Expand Down
2 changes: 1 addition & 1 deletion src/GHC/Util/HsExpr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Bag(bagToList)
import GHC.Util.Brackets
import GHC.Util.View
import GHC.Util.FreeVars
import GHC.Util.Outputable (unsafePrettyPrint)

import Control.Applicative
import Control.Monad.Trans.State
Expand All @@ -41,6 +40,7 @@ import qualified Refact.Types as R (SrcSpan)
import Language.Haskell.GhclibParserEx.GHC.Hs.Pat
import Language.Haskell.GhclibParserEx.GHC.Hs.Expr
import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances
import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable

-- | 'dotApp a b' makes 'a . b'.
dotApp' :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
Expand Down
14 changes: 0 additions & 14 deletions src/GHC/Util/Outputable.hs

This file was deleted.

3 changes: 2 additions & 1 deletion src/GHC/Util/Scope.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

Expand All @@ -16,7 +17,7 @@ import OccName

import GHC.Util.Module
import GHC.Util.RdrName
import GHC.Util.Outputable
import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable

import Data.List.Extra
import Data.Maybe
Expand Down
6 changes: 3 additions & 3 deletions src/GHC/Util/Unify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import Data.List.Extra
import Util

import GHC.Hs
import SrcLoc as GHC
import SrcLoc
import Outputable hiding ((<>))
import RdrName
import OccName

import Language.Haskell.GhclibParserEx.GHC.Hs.Pat
import Language.Haskell.GhclibParserEx.GHC.Hs.Expr
import GHC.Util.Outputable
import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable
import GHC.Util.HsExpr
import GHC.Util.RdrName
import GHC.Util.View
Expand Down Expand Up @@ -106,7 +106,7 @@ unify' nm root x y
| Just (x, y) <- cast (x, y) = unifyExp' nm root x y
| Just (x, y) <- cast (x, y) = unifyPat' nm x y
| Just (x, y) <- cast (x, y) = unifyType' nm x y
| Just (x :: GHC.SrcSpan) <- cast x = Just mempty
| Just (x :: SrcSpan) <- cast x = Just mempty
| otherwise = unifyDef' nm x y

unifyDef' :: Data a => NameMatch' -> a -> a -> Maybe (Subst' (LHsExpr GhcPs))
Expand Down
Loading

0 comments on commit b649373

Please sign in to comment.