Skip to content

Commit 15d8a38

Browse files
committed
ghc-lib-parser 9.10
1 parent 7e000cb commit 15d8a38

22 files changed

+256
-195
lines changed

cabal.project

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
packages: . extract-hackage-info
22

33
constraints: ormolu +dev
4+
5+
source-repository-package
6+
type: git
7+
location: https://github.com/amesgen/stuff
8+
tag: f0ef405ca08bfb3caf6562e9714f7fd51fa5f975
9+
subdir: ghc-lib-parser-9.10.1-alpha1
10+
--sha256: sha256-LCOIj4LDuW8JLdPRE3FXXkCwffJNao3wYzxpmKq1sT4=

flake.nix

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
inherit (pkgs) lib haskell-nix;
3737
inherit (haskell-nix) haskellLib;
3838

39-
ghcVersions = [ "ghc963" "ghc947" "ghc981" ];
39+
ghcVersions = [ "ghc963" "ghc981" ];
4040
defaultGHCVersion = builtins.head ghcVersions;
4141
perGHC = lib.genAttrs ghcVersions (ghcVersion:
4242
let
@@ -173,10 +173,12 @@
173173
nixConfig = {
174174
extra-substituters = [
175175
"https://cache.iog.io"
176+
"https://cache.zw3rk.com"
176177
"https://tweag-ormolu.cachix.org"
177178
];
178179
extra-trusted-public-keys = [
179180
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
181+
"loony-tools:pr9m4BkM/5/eSTZlkQyRt57Jz7OMBxNSUiMC4FkcNfk="
180182
"tweag-ormolu.cachix.org-1:3O4XG3o4AGquSwzzmhF6lov58PYG6j9zHcTDiROqkjM="
181183
];
182184
};

ormolu-live/cabal.project

+6
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ package ormolu
99
package ghc-lib-parser
1010
-- The WASM backend does not support the threaded RTS.
1111
flags: -threaded-rts
12+
13+
source-repository-package
14+
type: git
15+
location: https://github.com/amesgen/stuff
16+
tag: f0ef405ca08bfb3caf6562e9714f7fd51fa5f975
17+
subdir: ghc-lib-parser-9.10.1-alpha1

ormolu.cabal

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ library
110110
directory ^>=1.3,
111111
file-embed >=0.0.15 && <0.1,
112112
filepath >=1.2 && <1.5,
113-
ghc-lib-parser >=9.8 && <9.9,
113+
ghc-lib-parser >=9.10 && <9.11,
114114
megaparsec >=9,
115115
mtl >=2 && <3,
116116
syb >=0.7 && <0.8,
@@ -139,7 +139,7 @@ executable ormolu
139139
containers >=0.5 && <0.7,
140140
directory ^>=1.3,
141141
filepath >=1.2 && <1.5,
142-
ghc-lib-parser >=9.8 && <9.9,
142+
ghc-lib-parser >=9.10 && <9.11,
143143
optparse-applicative >=0.14 && <0.19,
144144
ormolu,
145145
text >=2 && <3,
@@ -178,7 +178,7 @@ test-suite tests
178178
containers >=0.5 && <0.7,
179179
directory ^>=1.3,
180180
filepath >=1.2 && <1.5,
181-
ghc-lib-parser >=9.8 && <9.9,
181+
ghc-lib-parser >=9.10 && <9.11,
182182
hspec >=2 && <3,
183183
hspec-megaparsec >=2.2,
184184
megaparsec >=9,

src/Ormolu/Diff/ParseResult.hs

+10-5
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,19 @@ diffHsModule = genericQuery
9393
`extQ` considerEqual @SourceText
9494
`extQ` hsDocStringEq
9595
`extQ` importDeclQualifiedStyleEq
96-
`extQ` considerEqual @(LayoutInfo GhcPs)
9796
`extQ` classDeclCtxEq
9897
`extQ` derivedTyClsParensEq
9998
`extQ` considerEqual @EpAnnComments -- ~ XCGRHSs GhcPs
10099
`extQ` considerEqual @TokenLocation -- in LHs(Uni)Token
101100
`extQ` considerEqual @EpaLocation
101+
`extQ` considerEqual @EpLayout
102+
`extQ` considerEqual @[AddEpAnn]
103+
`extQ` considerEqual @AnnSig
102104
`ext2Q` forLocated
103105
-- unicode-related
104-
`extQ` considerEqual @(HsUniToken "->" "")
105-
`extQ` considerEqual @(HsUniToken "::" "")
106-
`extQ` considerEqual @(HsLinearArrowTokens GhcPs)
106+
`extQ` considerEqual @(EpUniToken "->" "")
107+
`extQ` considerEqual @(EpUniToken "::" "")
108+
`extQ` considerEqual @EpLinearArrow
107109
)
108110
x
109111
y
@@ -141,7 +143,10 @@ diffHsModule = genericQuery
141143
GenLocated e0 e1 ->
142144
GenericQ ParseResultDiff
143145
forLocated x@(L mspn _) y =
144-
maybe id appendSpan (cast `ext1Q` (Just . locA) $ mspn) (genericQuery x y)
146+
maybe id appendSpan (cast `ext1Q` (Just . epAnnLoc) $ mspn) (genericQuery x y)
147+
where
148+
epAnnLoc :: EpAnn ann -> SrcSpan
149+
epAnnLoc = locA
145150
appendSpan :: SrcSpan -> ParseResultDiff -> ParseResultDiff
146151
appendSpan s' d@(Different ss) =
147152
case s' of

src/Ormolu/Fixity/Imports.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ extractFixityImport ImportDecl {..} =
6969

7070
ieToOccNames :: IE GhcPs -> [OccName]
7171
ieToOccNames = \case
72-
IEVar _ (L _ x) -> [occName x]
73-
IEThingAbs _ (L _ x) -> [occName x]
74-
IEThingAll _ (L _ x) -> [occName x] -- TODO not quite correct, but how to do better?
75-
IEThingWith _ (L _ x) _ xs -> occName x : fmap (occName . unLoc) xs
72+
IEVar _ (L _ x) _ -> [occName x]
73+
IEThingAbs _ (L _ x) _ -> [occName x]
74+
IEThingAll _ (L _ x) _ -> [occName x] -- TODO not quite correct, but how to do better?
75+
IEThingWith _ (L _ x) _ xs _ -> occName x : fmap (occName . unLoc) xs
7676
_ -> []
7777

7878
-- | Apply given module re-exports.

src/Ormolu/Fixity/Parser.hs

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ import Text.Megaparsec.Char.Lexer qualified as L
4545

4646
type Parser = Parsec Void Text
4747

48+
-- TODO support fixity namespacing?
49+
-- https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0065-type-infix.rst
50+
-- https://github.com/tweag/ormolu/pull/1029#issue-1718217029
51+
-- https://github.com/tweag/ormolu/pull/994#pullrequestreview-1396958951
52+
4853
-- | Parse textual representation of 'FixityOverrides'.
4954
parseDotOrmolu ::
5055
-- | Location of the file we are parsing (only for parse errors)

src/Ormolu/Imports.hs

+18-17
Original file line numberDiff line numberDiff line change
@@ -138,33 +138,34 @@ normalizeLies = sortOn (getIewn . unLoc) . M.elems . foldl' combine M.empty
138138
alter = \case
139139
Nothing -> Just . L new_l $
140140
case new of
141-
IEThingWith _ n wildcard g ->
142-
IEThingWith (Nothing, EpAnnNotUsed) n wildcard (normalizeWNames g)
141+
IEThingWith x n wildcard g _ ->
142+
IEThingWith x n wildcard (normalizeWNames g) Nothing
143143
other -> other
144144
Just old ->
145145
let f = \case
146-
IEVar _ n -> IEVar Nothing n
147-
IEThingAbs _ _ -> new
148-
IEThingAll _ n -> IEThingAll (Nothing, EpAnnNotUsed) n
149-
IEThingWith _ n wildcard g ->
146+
IEVar _ n _ -> IEVar Nothing n Nothing
147+
IEThingAbs _ _ _ -> new
148+
IEThingAll x n _ -> IEThingAll x n Nothing
149+
IEThingWith _ n wildcard g _ ->
150150
case new of
151-
IEVar _ _ ->
151+
IEVar _ _ _ ->
152152
error "Ormolu.Imports broken presupposition"
153-
IEThingAbs _ _ ->
154-
IEThingWith (Nothing, EpAnnNotUsed) n wildcard g
155-
IEThingAll _ n' ->
156-
IEThingAll (Nothing, EpAnnNotUsed) n'
157-
IEThingWith _ n' wildcard' g' ->
153+
IEThingAbs x _ _ ->
154+
IEThingWith x n wildcard g Nothing
155+
IEThingAll x n' _ ->
156+
IEThingAll x n' Nothing
157+
IEThingWith x n' wildcard' g' _ ->
158158
let combinedWildcard =
159159
case (wildcard, wildcard') of
160160
(IEWildcard _, _) -> IEWildcard 0
161161
(_, IEWildcard _) -> IEWildcard 0
162162
_ -> NoIEWildcard
163163
in IEThingWith
164-
(Nothing, EpAnnNotUsed)
164+
x
165165
n'
166166
combinedWildcard
167167
(normalizeWNames (g <> g'))
168+
Nothing
168169
IEModuleContents _ _ -> notImplemented "IEModuleContents"
169170
IEGroup NoExtField _ _ -> notImplemented "IEGroup"
170171
IEDoc NoExtField _ -> notImplemented "IEDoc"
@@ -187,10 +188,10 @@ instance Ord IEWrappedNameOrd where
187188
-- | Project @'IEWrappedName' 'GhcPs'@ from @'IE' 'GhcPs'@.
188189
getIewn :: IE GhcPs -> IEWrappedNameOrd
189190
getIewn = \case
190-
IEVar _ x -> IEWrappedNameOrd (unLoc x)
191-
IEThingAbs _ x -> IEWrappedNameOrd (unLoc x)
192-
IEThingAll _ x -> IEWrappedNameOrd (unLoc x)
193-
IEThingWith _ x _ _ -> IEWrappedNameOrd (unLoc x)
191+
IEVar _ x _ -> IEWrappedNameOrd (unLoc x)
192+
IEThingAbs _ x _ -> IEWrappedNameOrd (unLoc x)
193+
IEThingAll _ x _ -> IEWrappedNameOrd (unLoc x)
194+
IEThingWith _ x _ _ _ -> IEWrappedNameOrd (unLoc x)
194195
IEModuleContents _ _ -> notImplemented "IEModuleContents"
195196
IEGroup NoExtField _ _ -> notImplemented "IEGroup"
196197
IEDoc NoExtField _ -> notImplemented "IEDoc"

src/Ormolu/Parser.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ normalizeModule hsmod =
212212
patchContext :: LHsContext GhcPs -> LHsContext GhcPs
213213
patchContext = fmap $ \case
214214
[x@(L _ (HsParTy _ _))] -> [x]
215-
[x@(L lx _)] -> [L lx (HsParTy EpAnnNotUsed x)]
215+
[x@(L lx _)] -> [L lx (HsParTy noAnn x)]
216216
xs -> xs
217217

218218
-- | Enable all language extensions that we think should be enabled by

src/Ormolu/Parser/CommentStream.hs

+5-3
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ extractPragmas input = go initialLs id id
223223

224224
-- | Extract @'RealLocated' 'Text'@ from 'GHC.LEpaComment'.
225225
unAnnotationComment :: GHC.LEpaComment -> Maybe (RealLocated Text)
226-
unAnnotationComment (L (GHC.Anchor anchor _) (GHC.EpaComment eck _)) =
226+
unAnnotationComment (L epaLoc (GHC.EpaComment eck _)) =
227227
case eck of
228228
GHC.EpaDocComment s ->
229229
let trigger = case s of
@@ -239,9 +239,11 @@ unAnnotationComment (L (GHC.Anchor anchor _) (GHC.EpaComment eck _)) =
239239
"---" -> s
240240
_ -> insertAt " " s 3
241241
GHC.EpaBlockComment s -> mkL (T.pack s)
242-
GHC.EpaEofComment -> Nothing
243242
where
244-
mkL = Just . L anchor
243+
-- TODO mkL = L (GHC.epaLocationRealSrcSpan epaLoc)
244+
mkL = case epaLoc of
245+
GHC.EpaSpan (RealSrcSpan s _) -> Just . L s
246+
_ -> const Nothing
245247
insertAt x xs n = T.take (n - 1) xs <> x <> T.drop (n - 1) xs
246248
haddock mtrigger =
247249
mkL . dashPrefix . escapeHaddockTriggers . (trigger <>) <=< dropBlank

src/Ormolu/Printer/Combinators.hs

+6-6
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ import Control.Monad
7676
import Data.List (intersperse)
7777
import Data.Text (Text)
7878
import GHC.Data.Strict qualified as Strict
79+
import GHC.Parser.Annotation
7980
import GHC.Types.SrcLoc
8081
import Ormolu.Printer.Comments
8182
import Ormolu.Printer.Internal
82-
import Ormolu.Utils (HasSrcSpan (..), getLoc')
8383

8484
----------------------------------------------------------------------------
8585
-- Basic
@@ -99,13 +99,13 @@ inciIf b m = if b then inci m else m
9999
-- 'Located' wrapper, it should be “discharged” with a corresponding
100100
-- 'located' invocation.
101101
located ::
102-
(HasSrcSpan l) =>
102+
(HasLoc l) =>
103103
-- | Thing to enter
104104
GenLocated l a ->
105105
-- | How to render inner value
106106
(a -> R ()) ->
107107
R ()
108-
located (L l' a) f = case loc' l' of
108+
located (L l' a) f = case locA l' of
109109
UnhelpfulSpan _ -> f a
110110
RealSrcSpan l _ -> do
111111
spitPrecedingComments l
@@ -117,7 +117,7 @@ located (L l' a) f = case loc' l' of
117117
-- virtual elements at the start and end of the source span to prevent comments
118118
-- from "floating out".
119119
encloseLocated ::
120-
(HasSrcSpan l) =>
120+
(HasLoc l) =>
121121
GenLocated l [a] ->
122122
([a] -> R ()) ->
123123
R ()
@@ -126,13 +126,13 @@ encloseLocated la f = located la $ \a -> do
126126
f a
127127
when (null a) $ located (L endSpan ()) pure
128128
where
129-
l = getLoc' la
129+
l = locA la
130130
(startLoc, endLoc) = (srcSpanStart l, srcSpanEnd l)
131131
(startSpan, endSpan) = (mkSrcSpan startLoc startLoc, mkSrcSpan endLoc endLoc)
132132

133133
-- | A version of 'located' with arguments flipped.
134134
located' ::
135-
(HasSrcSpan l) =>
135+
(HasLoc l) =>
136136
-- | How to render inner value
137137
(a -> R ()) ->
138138
-- | Thing to enter

src/Ormolu/Printer/Meat/Common.hs

+19-13
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ module Ormolu.Printer.Meat.Common
1313
p_hsDoc,
1414
p_hsDocName,
1515
p_sourceText,
16+
p_namespaceSpec,
1617
)
1718
where
1819

1920
import Control.Monad
2021
import Data.Text qualified as T
2122
import GHC.Data.FastString
23+
import GHC.Hs.Binds
2224
import GHC.Hs.Doc
2325
import GHC.Hs.Extension (GhcPs)
2426
import GHC.Hs.ImpExp
@@ -66,18 +68,16 @@ p_ieWrappedName = \case
6668
p_rdrName :: LocatedN RdrName -> R ()
6769
p_rdrName l = located l $ \x -> do
6870
unboxedSums <- isExtensionEnabled UnboxedSums
69-
let wrapper = \case
70-
EpAnn {anns} -> case anns of
71-
NameAnnQuote {nann_quoted} -> tickPrefix . wrapper (ann nann_quoted)
72-
NameAnn {nann_adornment = NameParens} ->
73-
parens N . handleUnboxedSumsAndHashInteraction
74-
NameAnn {nann_adornment = NameBackquotes} -> backticks
75-
-- whether the `->` identifier is parenthesized
76-
NameAnnRArrow {nann_mopen = Just _} -> parens N
77-
-- special case for unboxed unit tuples
78-
NameAnnOnly {nann_adornment = NameParensHash} -> const $ txt "(# #)"
79-
_ -> id
80-
EpAnnNotUsed -> id
71+
let wrapper EpAnn {anns} = case anns of
72+
NameAnnQuote {nann_quoted} -> tickPrefix . wrapper nann_quoted
73+
NameAnn {nann_adornment = NameParens} ->
74+
parens N . handleUnboxedSumsAndHashInteraction
75+
NameAnn {nann_adornment = NameBackquotes} -> backticks
76+
-- whether the `->` identifier is parenthesized
77+
NameAnnRArrow {nann_mopen = Just _} -> parens N
78+
-- special case for unboxed unit tuples
79+
NameAnnOnly {nann_adornment = NameParensHash} -> const $ txt "(# #)"
80+
_ -> id
8181

8282
-- When UnboxedSums is enabled, `(#` is a single lexeme, so we have to
8383
-- insert spaces when we have a parenthesized operator starting with `#`.
@@ -88,7 +88,7 @@ p_rdrName l = located l $ \x -> do
8888
\y -> space *> y <* space
8989
| otherwise = id
9090

91-
wrapper (ann . getLoc $ l) $ case x of
91+
wrapper (getLoc l) $ case x of
9292
Unqual occName ->
9393
atom occName
9494
Qual mname occName ->
@@ -192,3 +192,9 @@ p_sourceText :: SourceText -> R ()
192192
p_sourceText = \case
193193
NoSourceText -> pure ()
194194
SourceText s -> atom @FastString s
195+
196+
p_namespaceSpec :: NamespaceSpecifier -> R ()
197+
p_namespaceSpec = \case
198+
NoNamespaceSpecifier -> pure ()
199+
TypeNamespaceSpecifier _ -> txt "type" *> space
200+
DataNamespaceSpecifier _ -> txt "data" *> space

src/Ormolu/Printer/Meat/Declaration.hs

+5-4
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ pattern AnnTypePragma n <- AnnD _ (HsAnnotation _ (TypeAnnProvenance (L _ n)) _)
260260
pattern AnnValuePragma n <- AnnD _ (HsAnnotation _ (ValueAnnProvenance (L _ n)) _)
261261
pattern Pattern n <- ValD _ (PatSynBind _ (PSB _ (L _ n) _ _ _))
262262
pattern DataDeclaration n <- TyClD _ (DataDecl _ (L _ n) _ _ _)
263-
pattern ClassDeclaration n <- TyClD _ (ClassDecl _ _ _ (L _ n) _ _ _ _ _ _ _ _)
263+
pattern ClassDeclaration n <- TyClD _ (ClassDecl _ _ (L _ n) _ _ _ _ _ _ _ _)
264264
pattern KindSignature n <- KindSigD _ (StandaloneKindSig _ (L _ n) _)
265265
pattern FamilyDeclaration n <- TyClD _ (FamDecl _ (FamilyDecl _ _ _ (L _ n) _ _ _ _))
266266
pattern TypeSynonym n <- TyClD _ (SynDecl _ (L _ n) _ _ _)
@@ -296,7 +296,7 @@ defSigRdrNames _ = Nothing
296296

297297
funRdrNames :: HsDecl GhcPs -> Maybe [RdrName]
298298
funRdrNames (ValD _ (FunBind _ (L _ n) _)) = Just [n]
299-
funRdrNames (ValD _ (PatBind _ (L _ n) _)) = Just $ patBindNames n
299+
funRdrNames (ValD _ (PatBind _ (L _ n) _ _)) = Just $ patBindNames n
300300
funRdrNames _ = Nothing
301301

302302
patSigRdrNames :: HsDecl GhcPs -> Maybe [RdrName]
@@ -315,9 +315,9 @@ patBindNames (VarPat _ (L _ n)) = [n]
315315
patBindNames (WildPat _) = []
316316
patBindNames (LazyPat _ (L _ p)) = patBindNames p
317317
patBindNames (BangPat _ (L _ p)) = patBindNames p
318-
patBindNames (ParPat _ _ (L _ p) _) = patBindNames p
318+
patBindNames (ParPat _ (L _ p)) = patBindNames p
319319
patBindNames (ListPat _ ps) = concatMap (patBindNames . unLoc) ps
320-
patBindNames (AsPat _ (L _ n) _ (L _ p)) = n : patBindNames p
320+
patBindNames (AsPat _ (L _ n) (L _ p)) = n : patBindNames p
321321
patBindNames (SumPat _ (L _ p) _ _) = patBindNames p
322322
patBindNames (ViewPat _ _ (L _ p)) = patBindNames p
323323
patBindNames (SplicePat _ _) = []
@@ -326,3 +326,4 @@ patBindNames (SigPat _ (L _ p) _) = patBindNames p
326326
patBindNames (NPat _ _ _ _) = []
327327
patBindNames (NPlusKPat _ (L _ n) _ _ _ _) = [n]
328328
patBindNames (ConPat _ _ d) = concatMap (patBindNames . unLoc) (hsConPatArgs d)
329+
patBindNames (EmbTyPat _ _) = [] -- TODO

0 commit comments

Comments
 (0)