google / ghc-source-gen

Library for generating Haskell source files and code fragments.
BSD 3-Clause "New" or "Revised" License
89 stars 29 forks source link

Support ghc 9.8 #108

Open blackgnezdo opened 8 months ago

blackgnezdo commented 8 months ago

I started on doing the 9.8 uprev and got stuck with:

src/GHC/SourceGen/Module.hs:182:29: error: [GHC-83865]
    • Couldn't match type: (Maybe
                              (GHC.Parser.Annotation.LocatedP
                                 (GHC.Unit.Module.Warnings.WarningTxt GhcPs)),
                            EpAnn [GHC.Parser.Annotation.AddEpAnn])
                     with: EpAnn ann2
      Expected: EpAnn ann2
                -> GenLocated SrcSpanAnnA (IEWrappedName GhcPs) -> IE'
        Actual: Language.Haskell.Syntax.Extension.XIEThingAll GhcPs
                -> Language.Haskell.Syntax.ImpExp.LIEWrappedName GhcPs -> IE GhcPs
    • In the first argument of ‘withEpAnnNotUsed’, namely ‘IEThingAll’
      In the first argument of ‘(.)’, namely
        ‘withEpAnnNotUsed IEThingAll’
      In the expression: withEpAnnNotUsed IEThingAll . wrappedName
    |
182 | thingAll = withEpAnnNotUsed IEThingAll . wrappedName
    |                             ^^^^^^^^^^

There's a type-checker change which causes the following behavior mismatch between 9.8 and 9.6. The old versions works:

λ> z = (undefined :: GenLocated SrcSpanAnnA (IEWrappedName GhcPs))
λ> :t ($ EpAnnNotUsed) IEThingAll z
($ EpAnnNotUsed) IEThingAll z :: IE GhcPs

the new one fails:

λ> z = (undefined :: GenLocated SrcSpanAnnA (IEWrappedName GhcPs))
λ> :t ($ EpAnnNotUsed) IEThingAll z

    • Couldn't match type: (Maybe
                              (GHC.Parser.Annotation.LocatedP
                                 (GHC.Unit.Module.Warnings.WarningTxt GhcPs)),
                            EpAnn [GHC.Parser.Annotation.AddEpAnn])
                     with: EpAnn ann0
      Expected: EpAnn ann0
                -> GenLocated SrcSpanAnnA (IEWrappedName GhcPs) -> IE GhcPs
        Actual: XIEThingAll GhcPs
                -> Language.Haskell.Syntax.ImpExp.LIEWrappedName GhcPs -> IE GhcPs
    • In the first argument of ‘$ EpAnnNotUsed’, namely ‘IEThingAll’
      In the expression: ($ EpAnnNotUsed) IEThingAll z

So if somebody is well-versed in type families, they should suggest a fix.

mattapet commented 6 months ago

hey @blackgnezdo 👋 since it's been some time since this was opened, I created a PR adding support for 9.8 (hopefully correctly 😅). The particular problem you mentioned was caused due to extending the annotation required in that particular place with additional information. I.e., making EpAnn ann into a (Maybe something, EpAnn ann), accounted for here.

If there's anything else you might be interested in, shoot a question! 🙂