Skip to content

Commit 55adfee

Browse files
authored
Merge pull request #1629 from ndmitchell/ghc-9.12.1
updates for compatibility with ghc-9.12
2 parents 7dfba72 + ae1695c commit 55adfee

26 files changed

+73
-93
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
os: [ubuntu-latest]
19-
ghc: ['9.10', '9.8', '9.6']
19+
ghc: ['9.12', '9.10', '9.8']
2020
include:
2121
- os: windows-latest
22-
ghc: '9.8'
22+
ghc: '9.10'
2323
- os: macOS-latest
24-
ghc: '9.8'
24+
ghc: '9.10'
2525
steps:
2626
- run: git config --global core.autocrlf false
2727
- uses: actions/checkout@v2
28-
- uses: haskell/actions/setup@v2
28+
- uses: haskell-actions/setup@v2
2929
id: setup-haskell
3030
with:
3131
ghc-version: ${{ matrix.ghc }}
3232
- run: cabal install apply-refact --install-method=copy
33-
if: matrix.ghc == '9.8' || matrix.ghc == '9.6'
33+
if: matrix.ghc == '9.8'
3434
- name: Get GHC libdir
3535
id: get-ghc-libdir
3636
run: echo "libdir=$(ghc --print-libdir)" >> $GITHUB_OUTPUT

hlint.cabal

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ library
8181
deriving-aeson >= 0.2,
8282
filepattern >= 0.1.1
8383

84-
if !flag(ghc-lib) && impl(ghc >= 9.10.1) && impl(ghc < 9.11.0)
84+
if !flag(ghc-lib) && impl(ghc >= 9.12.1) && impl(ghc < 9.13.0)
8585
build-depends:
86-
ghc == 9.10.*,
86+
ghc == 9.12.*,
8787
ghc-boot-th,
8888
ghc-boot
8989
else
9090
build-depends:
91-
ghc-lib-parser == 9.10.*
91+
ghc-lib-parser == 9.12.*
9292
build-depends:
93-
ghc-lib-parser-ex >= 9.10.0.0 && < 9.11.0
93+
ghc-lib-parser-ex >= 9.12.0.0 && < 9.13.0
9494

9595
if flag(gpl)
9696
build-depends: hscolour >= 1.21

src/Config/Compute.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Data.Generics.Uniplate.DataOnly
1212
import GHC.Hs hiding (Warning)
1313
import GHC.Types.Name.Reader
1414
import GHC.Types.Name
15-
import GHC.Data.Bag
1615
import GHC.Types.SrcLoc
1716
import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances
1817
import Language.Haskell.GhclibParserEx.GHC.Hs.Expr
@@ -46,7 +45,7 @@ renderSetting _ = []
4645
findSetting :: LocatedA (HsDecl GhcPs) -> [Setting]
4746
findSetting (L _ (ValD _ x)) = findBind x
4847
findSetting (L _ (InstD _ (ClsInstD _ ClsInstDecl{cid_binds}))) =
49-
concatMap (findBind . unLoc) $ bagToList cid_binds
48+
concatMap (findBind . unLoc) cid_binds
5049
findSetting (L _ (SigD _ (FixSig _ x))) = map Infix $ fromFixitySig x
5150
findSetting x = []
5251

@@ -57,9 +56,9 @@ findBind FunBind{fun_id, fun_matches} = findExp (unLoc fun_id) [] $ HsLam noAnn
5756
findBind _ = []
5857

5958
findExp :: IdP GhcPs -> [String] -> HsExpr GhcPs -> [Setting]
60-
findExp name vs (HsLam _ LamSingle MG{mg_alts=L _ [L _ Match{m_pats, m_grhss=GRHSs{grhssGRHSs=[L _ (GRHS _ [] x)], grhssLocalBinds=(EmptyLocalBinds _)}}]})
61-
= if length m_pats == length ps then findExp name (vs++ps) $ unLoc x else []
62-
where ps = [rdrNameStr x | L _ (VarPat _ x) <- m_pats]
59+
findExp name vs (HsLam _ LamSingle MG{mg_alts=L _ [L _ Match{m_pats=L _ pats, m_grhss=GRHSs{grhssGRHSs=[L _ (GRHS _ [] x)], grhssLocalBinds=(EmptyLocalBinds _)}}]})
60+
= if length pats == length ps then findExp name (vs++ps) $ unLoc x else []
61+
where ps = [rdrNameStr x | L _ (VarPat _ x) <- pats]
6362
findExp name vs HsLam{} = []
6463
findExp name vs HsVar{} = []
6564
findExp name vs (OpApp _ x dot y) | isDot dot = findExp name (vs++["_hlint"]) $

src/Config/Haskell.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ errorOn (L pos val) msg = exitMessageImpure $
8585
errorOnComment :: LEpaComment -> String -> b
8686
errorOnComment c@(L s _) msg = exitMessageImpure $
8787
let isMultiline = isCommentMultiline c in
88-
showSrcSpan (RealSrcSpan (anchor s) GHC.Data.Strict.Nothing) ++
88+
showSrcSpan (RealSrcSpan (epaLocationRealSrcSpan s) GHC.Data.Strict.Nothing) ++
8989
": Error while reading hint file, " ++ msg ++ "\n" ++
9090
(if isMultiline then "{-" else "--") ++ commentText c ++ (if isMultiline then "-}" else "")

src/Fixity.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import GHC.Hs.Extension
1212
import GHC.Types.Name.Occurrence
1313
import GHC.Types.Name.Reader
1414
import GHC.Types.Fixity
15-
import GHC.Types.SourceText
1615
import GHC.Parser.Annotation
1716
import Language.Haskell.GhclibParserEx.GHC.Types.Name.Reader
1817
import Language.Haskell.GhclibParserEx.Fixity
@@ -28,22 +27,22 @@ import Language.Haskell.GhclibParserEx.Fixity
2827
type FixityInfo = (String, Associativity, Int)
2928

3029
fromFixitySig :: FixitySig GhcPs -> [FixityInfo]
31-
fromFixitySig (FixitySig _ names (Fixity _ i dir)) =
30+
fromFixitySig (FixitySig _ names (Fixity i dir)) =
3231
[(rdrNameStr name, f dir, i) | name <- names]
3332
where
3433
f InfixL = LeftAssociative
3534
f InfixR = RightAssociative
3635
f InfixN = NotAssociative
3736

3837
toFixity :: FixityInfo -> (String, Fixity)
39-
toFixity (name, dir, i) = (name, Fixity NoSourceText i $ f dir)
38+
toFixity (name, dir, i) = (name, Fixity i $ f dir)
4039
where
4140
f LeftAssociative = InfixL
4241
f RightAssociative = InfixR
4342
f NotAssociative = InfixN
4443

4544
fromFixity :: (String, Fixity) -> FixityInfo
46-
fromFixity (name, Fixity _ i dir) = (name, assoc dir, i)
45+
fromFixity (name, Fixity i dir) = (name, assoc dir, i)
4746
where
4847
assoc dir = case dir of
4948
InfixL -> LeftAssociative

src/GHC/Util/ApiAnnotation.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ languagePragmas ps =
107107
-- Given a list of flags, make a GHC options pragma.
108108
mkFlags :: NoCommentsLocation -> [String] -> LEpaComment
109109
mkFlags anc flags =
110-
L anc $ EpaComment (EpaBlockComment ("{-# " ++ "OPTIONS_GHC " ++ unwords flags ++ " #-}")) (anchor anc)
110+
L anc $ EpaComment (EpaBlockComment ("{-# " ++ "OPTIONS_GHC " ++ unwords flags ++ " #-}")) (epaLocationRealSrcSpan anc)
111111

112112
mkLanguagePragmas :: NoCommentsLocation -> [String] -> LEpaComment
113113
mkLanguagePragmas anc exts =
114-
L anc $ EpaComment (EpaBlockComment ("{-# " ++ "LANGUAGE " ++ intercalate ", " exts ++ " #-}")) (anchor anc)
114+
L anc $ EpaComment (EpaBlockComment ("{-# " ++ "LANGUAGE " ++ intercalate ", " exts ++ " #-}")) (epaLocationRealSrcSpan anc)

src/GHC/Util/Brackets.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ instance Brackets (LocatedA (HsExpr GhcPs)) where
3636
isAtom (L _ x) = case x of
3737
HsVar{} -> True
3838
HsUnboundVar{} -> True
39-
-- Technically atomic, but lots of people think it shouldn't be
40-
HsRecSel{} -> False
4139
-- Only relevant for OverloadedRecordDot extension
4240
HsGetField{} -> True
4341
HsOverLabel{} -> True

src/GHC/Util/FreeVars.hs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import GHC.Types.Name.Occurrence
1313
import GHC.Types.Name
1414
import GHC.Hs
1515
import GHC.Types.SrcLoc
16-
import GHC.Data.Bag (bagToList)
1716

1817
import Data.Generics.Uniplate.DataOnly
1918
import Data.Monoid
@@ -119,7 +118,7 @@ instance FreeVars (LocatedA (HsExpr GhcPs)) where
119118
_ -> mempty
120119
)
121120
accFree = accFree0 ^+ (free (allVars stmt) ^- accBound0)
122-
freeVars (L _ (RecordCon _ _ (HsRecFields flds _))) = Set.unions $ map freeVars flds -- Record construction.
121+
freeVars (L _ (RecordCon _ _ (HsRecFields _ flds _))) = Set.unions $ map freeVars flds -- Record construction.
123122
freeVars (L _ (RecordUpd _ e flds)) =
124123
case flds of
125124
RegularRecUpdFields _ fs -> Set.unions $ freeVars e : map freeVars fs
@@ -129,7 +128,6 @@ instance FreeVars (LocatedA (HsExpr GhcPs)) where
129128
freeVars (L _ (HsUntypedBracket _ (ExpBr _ e))) = freeVars e
130129
freeVars (L _ (HsUntypedBracket _ (VarBr _ _ v))) = Set.fromList [occName (unLoc v)]
131130

132-
freeVars (L _ HsRecSel{}) = mempty -- Variable pointing to a record selector.
133131
freeVars (L _ HsOverLabel{}) = mempty -- Overloaded label. The id of the in-scope fromLabel.
134132
freeVars (L _ HsIPVar{}) = mempty -- Implicit parameter.
135133
freeVars (L _ HsOverLit{}) = mempty -- Overloaded literal.
@@ -173,23 +171,19 @@ instance FreeVars (LocatedA (HsFieldBind (LocatedA (FieldOcc GhcPs)) (LocatedA (
173171
freeVars o@(L _ (HsFieldBind _ x _ True)) = Set.singleton $ occName $ unLoc $ foLabel $ unLoc x -- a pun
174172
freeVars o@(L _ (HsFieldBind _ _ x _)) = freeVars x
175173

176-
instance FreeVars (LocatedA (HsFieldBind (LocatedA (AmbiguousFieldOcc GhcPs)) (LocatedA (HsExpr GhcPs)))) where
177-
freeVars (L _ (HsFieldBind _ x _ True)) = Set.singleton $ rdrNameOcc $ ambiguousFieldOccRdrName $ unLoc x -- a pun
178-
freeVars (L _ (HsFieldBind _ _ x _)) = freeVars x
179-
180174
instance FreeVars (LocatedA (HsFieldBind (LocatedAn NoEpAnns (FieldLabelStrings GhcPs)) (LocatedA (HsExpr GhcPs)))) where
181175
freeVars (L _ (HsFieldBind _ _ x _)) = freeVars x
182176

183177
instance AllVars (LocatedA (Pat GhcPs)) where
184178
allVars (L _ (VarPat _ (L _ x))) = Vars (Set.singleton $ rdrNameOcc x) Set.empty -- Variable pattern.
185179
allVars (L _ (AsPat _ n x)) = allVars (noLocA $ VarPat noExtField n :: LocatedA (Pat GhcPs)) <> allVars x -- As pattern.
186-
allVars (L _ (ConPat _ _ (RecCon (HsRecFields flds _)))) = allVars flds
180+
allVars (L _ (ConPat _ _ (RecCon (HsRecFields _ flds _)))) = allVars flds
187181
allVars (L _ (NPlusKPat _ n _ _ _ _)) = allVars (noLocA $ VarPat noExtField n :: LocatedA (Pat GhcPs)) -- n+k pattern.
188182
allVars (L _ (ViewPat _ e p)) = freeVars_ e <> allVars p -- View pattern.
189-
190183
allVars (L _ WildPat{}) = mempty -- Wildcard pattern.
191184
allVars (L _ LitPat{}) = mempty -- Literal pattern.
192185
allVars (L _ NPat{}) = mempty -- Natural pattern.
186+
allVars (L _ InvisPat {}) = mempty -- since ghc-9.10.1
193187

194188
-- allVars p@SplicePat{} = allVars $ children p -- Splice pattern (includes quasi-quotes).
195189
-- allVars p@SigPat{} = allVars $ children p -- Pattern with a type signature.
@@ -213,12 +207,10 @@ instance AllVars (LocatedA (StmtLR GhcPs GhcPs (LocatedA (HsExpr GhcPs)))) where
213207
allVars (L _ (LetStmt _ binds)) = allVars binds -- A local declaration e.g. let y = x + 1
214208
allVars (L _ (TransStmt _ _ stmts _ using by _ _ fmap_)) = allVars stmts <> freeVars_ using <> maybe mempty freeVars_ by <> freeVars_ (noLocA fmap_ :: LocatedA (HsExpr GhcPs)) -- Apply a function to a list of statements in order.
215209
allVars (L _ (RecStmt _ stmts _ _ _ _ _)) = allVars (unLoc stmts) -- A recursive binding for a group of arrows.
216-
217-
allVars (L _ ApplicativeStmt{}) = mempty -- Generated by the renamer.
218210
allVars (L _ ParStmt{}) = mempty -- Parallel list thing. Come back to it.
219211

220212
instance AllVars (HsLocalBinds GhcPs) where
221-
allVars (HsValBinds _ (ValBinds _ binds _)) = allVars (bagToList binds) -- Value bindings.
213+
allVars (HsValBinds _ (ValBinds _ binds _)) = allVars binds -- Value bindings.
222214
allVars (HsIPBinds _ (IPBinds _ binds)) = allVars binds -- Implicit parameter bindings.
223215
allVars EmptyLocalBinds{} = mempty -- The case of no local bindings (signals the empty `let` or `where` clause).
224216
allVars _ = mempty -- extension points
@@ -233,13 +225,13 @@ instance AllVars (LocatedA (HsBindLR GhcPs GhcPs)) where
233225
allVars (L _ (PatSynBind _ PSB{})) = mempty -- Come back to it.
234226

235227
instance AllVars (MatchGroup GhcPs (LocatedA (HsExpr GhcPs))) where
236-
allVars (MG _ _alts@(L _ alts)) = foldMap (\m -> inVars (allVars (m_pats m)) (allVars (m_grhss m))) ms
228+
allVars (MG _ _alts@(L _ alts)) = foldMap (\m -> inVars (allVars ((unLoc . m_pats) m)) (allVars (m_grhss m))) ms
237229
where ms = map unLoc alts
238230

239231
instance AllVars (LocatedA (Match GhcPs (LocatedA (HsExpr GhcPs)))) where
240-
allVars (L _ (Match _ FunRhs {mc_fun=name} pats grhss)) = allVars (noLocA $ VarPat noExtField name :: LocatedA (Pat GhcPs)) <> allVars pats <> allVars grhss -- A pattern matching on an argument of a function binding.
241-
allVars (L _ (Match _ (StmtCtxt ctxt) pats grhss)) = allVars ctxt <> allVars pats <> allVars grhss -- Pattern of a do-stmt, list comprehension, pattern guard etc.
242-
allVars (L _ (Match _ _ pats grhss)) = inVars (allVars pats) (allVars grhss) -- Everything else.
232+
allVars (L _ (Match _ FunRhs {mc_fun=name} pats grhss)) = allVars (noLocA $ VarPat noExtField name :: LocatedA (Pat GhcPs)) <> (allVars . unLoc) pats <> allVars grhss -- A pattern matching on an argument of a function binding.
233+
allVars (L _ (Match _ (StmtCtxt ctxt) pats grhss)) = allVars ctxt <> (allVars . unLoc) pats <> allVars grhss -- Pattern of a do-stmt, list comprehension, pattern guard etc.
234+
allVars (L _ (Match _ _ pats grhss)) = inVars ((allVars . unLoc) pats) (allVars grhss) -- Everything else.
243235

244236
instance AllVars (HsStmtContext (GenLocated SrcSpanAnnN RdrName)) where
245237
allVars (PatGuard FunRhs{mc_fun=n}) = allVars (noLocA $ VarPat noExtField n :: LocatedA (Pat GhcPs))

src/GHC/Util/HsExpr.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import GHC.Types.SrcLoc
2121
import GHC.Data.FastString
2222
import GHC.Types.Name.Reader
2323
import GHC.Types.Name.Occurrence
24-
import GHC.Data.Bag(bagToList)
2524

2625
import GHC.Util.Brackets
2726
import GHC.Util.FreeVars
@@ -49,7 +48,7 @@ import Language.Haskell.GhclibParserEx.GHC.Types.Name.Reader
4948

5049
-- | 'dotApp a b' makes 'a . b'.
5150
dotApp :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
52-
dotApp x y = noLocA $ OpApp noAnn x (noLocA $ HsVar noExtField (noLocA $ mkVarUnqual (fsLit "."))) y
51+
dotApp x y = noLocA $ OpApp noExtField x (noLocA $ HsVar noExtField (noLocA $ mkVarUnqual (fsLit "."))) y
5352

5453
dotApps :: [LHsExpr GhcPs] -> LHsExpr GhcPs
5554
dotApps [] = error "GHC.Util.HsExpr.dotApps', does not work on an empty list"
@@ -58,7 +57,7 @@ dotApps (x : xs) = dotApp x (dotApps xs)
5857

5958
-- | @lambda [p0, p1..pn] body@ makes @\p1 p1 .. pn -> body@
6059
lambda :: [LPat GhcPs] -> LHsExpr GhcPs -> LHsExpr GhcPs
61-
lambda vs body = noLocA $ HsLam noAnn LamSingle (MG (Generated OtherExpansion DoPmc) (noLocA [noLocA $ Match noAnn (LamAlt LamSingle) vs (GRHSs emptyComments [noLocA $ GRHS noAnn [] body] (EmptyLocalBinds noExtField))]))
60+
lambda vs body = noLocA $ HsLam noAnn LamSingle (MG (Generated OtherExpansion DoPmc) (noLocA [noLocA $ Match noExtField (LamAlt LamSingle) (L noSpanAnchor vs) (GRHSs emptyComments [noLocA $ GRHS noAnn [] body] (EmptyLocalBinds noExtField))]))
6261

6362
-- | 'paren e' wraps 'e' in parens if 'e' is non-atomic.
6463
paren :: LHsExpr GhcPs -> LHsExpr GhcPs
@@ -124,8 +123,8 @@ simplifyExp :: LHsExpr GhcPs -> LHsExpr GhcPs
124123
simplifyExp (L l (OpApp _ x op y)) | isDol op = L l (HsApp noExtField x (nlHsPar y))
125124
simplifyExp e@(L _ (HsLet _ ((HsValBinds _ (ValBinds _ binds []))) z)) =
126125
-- An expression of the form, 'let x = y in z'.
127-
case bagToList binds of
128-
[L _ (FunBind _ _ (MG _ (L _ [L _ (Match _(FunRhs (L _ x) _ _) [] (GRHSs _[L _ (GRHS _ [] y)] ((EmptyLocalBinds _))))])))]
126+
case binds of
127+
[L _ (FunBind _ _ (MG _ (L _ [L _ (Match _(FunRhs (L _ x) _ _ _) (L _ []) (GRHSs _ [L _ (GRHS _ [] y)] ((EmptyLocalBinds _))))])))]
129128
-- If 'x' is not in the free variables of 'y', beta-reduce to
130129
-- 'z[(y)/x]'.
131130
| occNameStr x `notElem` vars y && length [() | Unqual a <- universeBi z, a == rdrNameOcc x] <= 1 ->
@@ -241,7 +240,7 @@ niceLambdaR [] e = (e, \s -> [Replace Expr s [("a", toSSA e)] "a"])
241240
niceLambdaR ss e =
242241
let grhs = noLocA $ GRHS noAnn [] e :: LGRHS GhcPs (LHsExpr GhcPs)
243242
grhss = GRHSs {grhssExt = emptyComments, grhssGRHSs=[grhs], grhssLocalBinds=EmptyLocalBinds noExtField}
244-
match = noLocA $ Match {m_ext=noAnn, m_ctxt=LamAlt LamSingle, m_pats=map strToPat ss, m_grhss=grhss} :: LMatch GhcPs (LHsExpr GhcPs)
243+
match = noLocA $ Match {m_ext=noExtField, m_ctxt=LamAlt LamSingle, m_pats=noLocA $ map strToPat ss, m_grhss=grhss} :: LMatch GhcPs (LHsExpr GhcPs)
245244
matchGroup = MG {mg_ext=Generated OtherExpansion SkipPmc, mg_alts=noLocA [match]}
246245
in (noLocA $ HsLam noAnn LamSingle matchGroup, const [])
247246

@@ -260,7 +259,7 @@ replaceBranches (L s (HsCase _ a (MG FromSource (L l bs)))) =
260259

261260
g :: [LMatch GhcPs (LHsExpr GhcPs)] -> [LHsExpr GhcPs] -> [LMatch GhcPs (LHsExpr GhcPs)]
262261
g (L s1 (Match _ CaseAlt a (GRHSs _ ns b)) : rest) xs =
263-
L s1 (Match noAnn CaseAlt a (GRHSs emptyComments [L a (GRHS noAnn gs x) | (L a (GRHS _ gs _), x) <- zip ns as] b)) : g rest bs
262+
L s1 (Match noExtField CaseAlt a (GRHSs emptyComments [L a (GRHS noAnn gs x) | (L a (GRHS _ gs _), x) <- zip ns as] b)) : g rest bs
264263
where (as, bs) = splitAt (length ns) xs
265264
g [] [] = []
266265
g _ _ = error "GHC.Util.HsExpr.replaceBranches': internal invariant failed, lists are of differing lengths"

src/GHC/Util/Scope.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ possImport (L _ i) (L _ (Unqual x)) =
119119
then maybe PossiblyImported (f . first (== EverythingBut)) (ideclImportList i)
120120
else NotImported
121121
where
122-
f :: (Bool, LocatedL [LIE GhcPs]) -> IsImported
122+
f :: (Bool, LocatedLI [LocatedA (IE GhcPs)]) -> IsImported
123123
f (hide, L _ xs)
124124
| hide = if Just True `elem` ms then NotImported else PossiblyImported
125125
| Just True `elem` ms = Imported

0 commit comments

Comments
 (0)