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.6 #103

Closed avdv closed 9 months ago

avdv commented 10 months ago

~Note, this is based on PR #102~

I did run cabal test with GHC 9.2.8, 9.4.6 and 9.6.2.

Note: using this with proto-lens-protoc, results in an Access Violation on Windows:

ERROR: D:/a/rules_haskell/rules_haskell/rule_info/BUILD.bazel:4:14: HaskellProtoc rule_info/Proto/RuleInfo.hs failed: (Exit 1): protoc.cmd failed: error executing command (from target //rule_info:rule_info_proto) 
  cd /d C:/_bzl/minshlu6/execroot/rules_haskell
  SET RULES_HASKELL_DOCDIR_PATH=external/rules_haskell_ghc_windows_amd64/doc/html/libraries/base-4.18.0.0
    SET RULES_HASKELL_GHC_PATH=external/rules_haskell_ghc_windows_amd64/bin/ghc-9.6.2.exe
    SET RULES_HASKELL_GHC_PKG_PATH=external/rules_haskell_ghc_windows_amd64/bin/ghc-pkg-9.6.2.exe
    SET RULES_HASKELL_LIBDIR_PATH=external/rules_haskell_ghc_windows_amd64/lib
  bazel-out\x64_windows-opt-exec-2B5CBBC6\bin\tests\protoc.cmd --plugin=protoc-gen-haskell=bazel-out/x64_windows-opt-exec-2B5CBBC6/bin/external/stackage/proto-lens-protoc-0.7.1.1/_install/bin/proto-lens-protoc.exe -Irule_info.proto=bazel-out/x64_windows-fastbuild/bin/rule_info/_virtual_imports/rule_info_proto/rule_info.proto bazel-out/x64_windows-fastbuild/bin/rule_info/_virtual_imports/rule_info_proto/rule_info.proto --proto_path=bazel-out/x64_windows-fastbuild/bin/rule_info/_virtual_imports/rule_info_proto --haskell_out=no-runtime:bazel-out/x64_windows-fastbuild/bin/rule_info
# Configuration: 58805939f72ec32a9a01431f857cb944cd1989989a33202e99fc6941d5e9061b
# Execution platform: @local_config_platform//:host

Access violation in generated code when executing data at 0x7ff72099960d

 Attempting to reconstruct a stack trace...

   Frame    Code address
 * 0x1f5c70d5f0 0x7ff72099960d
 * 0x1f5c70d5f8 0x7ff800000a77
 * 0x1f5c70d600 0x1645e17f5d0

--haskell_out: protoc-gen-haskell: Plugin failed with status code 11.

I am not sure this is related to this change...

blackgnezdo commented 10 months ago

Thanks for the change. I took it for a spin with 9.6.3. As you noted cabal test works fine. Sadly stack test is still broken. I pushed a couple of quick commits on top of your change to https://github.com/blackgnezdo/ghc-source-gen/pull/new/ghc-9.6

The errors I'm getting now are:

Stack has not been tested with GHC versions above 9.4, and using 9.6.3, this may fail
Stack has not been tested with Cabal versions above 3.8, but version 3.10.1.0 was found, this may fail

Building all executables for `ghc-show-ast' once. After a successful build of all of them, only specified executables will be rebuilt.
ghc-show-ast  > configure (exe)
ghc-show-ast  > Configuring ghc-show-ast-0.0.0...
ghc-show-ast  > build (exe)
ghc-source-gen> configure (lib + test)
ghc-source-gen> Configuring ghc-source-gen-0.4.3.0...
ghc-show-ast  > Preprocessing executable 'ghc-show-ast' for ghc-show-ast-0.0.0..
ghc-show-ast  > Building executable 'ghc-show-ast' for ghc-show-ast-0.0.0..
ghc-show-ast  > [1 of 2] Compiling Main
ghc-show-ast  > 
ghc-show-ast  > /home/greg/s/ghc-source-gen/ghc-show-ast/Main.hs:142:30: error: [GHC-76037]
ghc-show-ast  >     Not in scope: ‘Error.pprError’
ghc-show-ast  >     NB: neither ‘GHC.Driver.Errors’ nor ‘GHC.Parser.Errors.Ppr’ export ‘pprError’.
ghc-show-ast  >     |
ghc-show-ast  > 142 |                 let errors = Error.pprError <$> GHC.getErrorMessages s
ghc-show-ast  >     |                              ^^^^^^^^^^^^^^
ghc-show-ast  > 
ghc-show-ast  > /home/greg/s/ghc-source-gen/ghc-show-ast/Main.hs:142:49: error: [GHC-76037]
ghc-show-ast  >     Not in scope: ‘GHC.getErrorMessages’
ghc-show-ast  >     NB: neither ‘GHC’, ‘GHC.Data.FastString’, ‘GHC.Data.StringBuffer’,
ghc-show-ast  >                 ‘GHC.Driver.Monad’, ‘GHC.Driver.Session’, ‘GHC.Parser.Header’,
ghc-show-ast  >                 ‘GHC.Parser.Lexer’ nor ‘GHC.Types.SrcLoc’ export ‘getErrorMessages’.
ghc-show-ast  >     Suggested fix:
ghc-show-ast  >       Perhaps use one of these:
ghc-show-ast  >         ‘GHC.getPsErrorMessages’ (imported from GHC.Parser.Lexer),
ghc-show-ast  >         ‘GHC.getPsMessages’ (imported from GHC.Parser.Lexer)
ghc-show-ast  >     |
ghc-show-ast  > 142 |                 let errors = Error.pprError <$> GHC.getErrorMessages s
ghc-show-ast  >     |                                                 ^^^^^^^^^^^^^^^^^^^^
ghc-show-ast  > 
ghc-show-ast  > /home/greg/s/ghc-source-gen/ghc-show-ast/Main.hs:143:17: error: [GHC-76037]
ghc-show-ast  >     Not in scope: ‘Error.printBagOfErrors’
ghc-show-ast  >     NB: neither ‘GHC.Driver.Errors’ nor ‘GHC.Parser.Errors.Ppr’ export ‘printBagOfErrors’.
ghc-show-ast  >     |
ghc-show-ast  > 143 |                 Error.printBagOfErrors logger dflags errors
ghc-show-ast  >     |                 ^^^^^^^^^^^^^^^^^^^^^^
ghc-source-gen> build (lib + test)
ghc-source-gen> Preprocessing library for ghc-source-gen-0.4.3.0..
ghc-source-gen> Building library for ghc-source-gen-0.4.3.0..
ghc-source-gen> [ 7 of 18] Compiling GHC.SourceGen.Module
ghc-source-gen> 
ghc-source-gen> /home/greg/s/ghc-source-gen/src/GHC/SourceGen/Module.hs:30:7: error: [-Wunused-imports, Werror=unused-imports]
ghc-source-gen>     The import of ‘LIEWrappedName’
ghc-source-gen> [ 8 of 18] Compiling GHC.SourceGen.Lit
ghc-source-gen>     from module ‘GHC.Hs.ImpExp’ is redundant
ghc-source-gen>    |
ghc-source-gen> 30 |     ( LIEWrappedName, IEWildcard(..), IEWrappedName(..), IE(..)
ghc-source-gen>    |       ^^^^^^^^^^^^^^
ghc-source-gen> 
ghc-source-gen> [ 9 of 18] Compiling GHC.SourceGen.Expr.Internal
ghc-source-gen> /home/greg/s/ghc-source-gen/src/GHC/SourceGen/Module.hs:45:60: error: [-Wunused-imports, Werror=unused-imports]
ghc-source-gen>     The import of ‘AnnKeywordId’ from module ‘GHC.Hs’ is redundant
ghc-source-gen> [10 of 18] Compiling GHC.SourceGen.Binds.Internal
ghc-source-gen>    |
ghc-source-gen> 45 |     , hsmodDeprecMessage, hsmodHaddockModHeader, hsmodAnn, AnnKeywordId, XModulePs (XModulePs, hsmodLayout), noAnn, LayoutInfo (NoLayoutInfo), GhcPs, XImportDeclPass (XImportDeclPass, ideclAnn), SrcSpanAnnA, noExtField
ghc-source-gen>    |                                                            ^^^^^^^^^^^^
ghc-source-gen> 
ghc-source-gen> /home/greg/s/ghc-source-gen/src/GHC/SourceGen/Module.hs:53:1: error: [-Wunused-imports, Werror=unused-imports]
ghc-source-gen>     The import of ‘GHC.Types.Name.Reader’ is redundant
ghc-source-gen>       except perhaps to import instances from ‘GHC.Types.Name.Reader’
ghc-source-gen>     To import instances alone, use: import GHC.Types.Name.Reader()
ghc-source-gen>    |
ghc-source-gen> 53 | import GHC.Types.Name.Reader (RdrName)
ghc-source-gen>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ghc-source-gen> 
ghc-source-gen> /home/greg/s/ghc-source-gen/src/GHC/SourceGen/Module.hs:62:1: error: [-Wunused-imports, Werror=unused-imports]
ghc-source-gen>     The import of ‘ModuleNameStr, OccNameStr, RdrNameStr,
ghc-source-gen>                    ModuleNameStr(unModuleNameStr)’
ghc-source-gen> [12 of 18] Compiling GHC.SourceGen.Type
ghc-source-gen>     from module ‘GHC.SourceGen.Name’ is redundant
ghc-source-gen> [13 of 18] Compiling GHC.SourceGen.Pat
ghc-source-gen>    |
ghc-source-gen> 62 | import GHC.SourceGen.Name
ghc-source-gen>    | ^^^^^^^^^^^^^^^^^^^^^^^^^...
ghc-source-gen> 
ghc-source-gen> /home/greg/s/ghc-source-gen/src/GHC/SourceGen/Module.hs:65:1: error: [-Wunused-imports, Werror=unused-imports]
ghc-source-gen>     The import of ‘GHC.SourceGen.Lit.Internal’ is redundant
ghc-source-gen>       except perhaps to import instances from ‘GHC.SourceGen.Lit.Internal’
ghc-source-gen>     To import instances alone, use: import GHC.SourceGen.Lit.Internal()
ghc-source-gen>    |
ghc-source-gen> 65 | import GHC.SourceGen.Lit.Internal (noSourceText)
ghc-source-gen>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ghc-source-gen> 
ghc-source-gen> /home/greg/s/ghc-source-gen/src/GHC/SourceGen/Lit.hs:31:21: error: [-Wunused-imports, Werror=unused-imports]
ghc-source-gen>     The import of ‘noExpr’ from module ‘GHC.Hs.Expr’ is redundant
ghc-source-gen>    |
ghc-source-gen> 31 | import GHC.Hs.Expr (noExpr, noSyntaxExpr, HsExpr(..))
ghc-source-gen>    |                     ^^^^^^
ghc-source-gen> 
ghc-source-gen> /home/greg/s/ghc-source-gen/src/GHC/SourceGen/Expr/Internal.hs:21:1: error: [-Wunused-imports, Werror=unused-imports]
ghc-source-gen>     The import of ‘Language.Haskell.Syntax.Extension’ is redundant
ghc-source-gen>       except perhaps to import instances from ‘Language.Haskell.Syntax.Extension’
ghc-source-gen>     To import instances alone, use: import Language.Haskell.Syntax.Extension()
ghc-source-gen>    |
ghc-source-gen> 21 | import Language.Haskell.Syntax.Extension
ghc-source-gen>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ghc-source-gen> 
ghc-source-gen> /home/greg/s/ghc-source-gen/src/GHC/SourceGen/Binds/Internal.hs:27:1: error: [-Wunused-imports, Werror=unused-imports]
ghc-source-gen>     The import of ‘GHC’ is redundant
ghc-source-gen>       except perhaps to import instances from ‘GHC’
ghc-source-gen>     To import instances alone, use: import GHC()
ghc-source-gen>    |
ghc-source-gen> 27 | import GHC (noExtField, NoExtField (NoExtField))
ghc-source-gen>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ghc-source-gen> 
ghc-source-gen> /home/greg/s/ghc-source-gen/src/GHC/SourceGen/Type.hs:27:1: error: [-Wunused-imports, Werror=unused-imports]
ghc-source-gen>     The import of ‘GHC.Parser.Annotation’ is redundant
ghc-source-gen>       except perhaps to import instances from ‘GHC.Parser.Annotation’
ghc-source-gen>     To import instances alone, use: import GHC.Parser.Annotation()
ghc-source-gen>    |
ghc-source-gen> 27 | import GHC.Parser.Annotation
ghc-source-gen>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ghc-source-gen> 
ghc-source-gen> /home/greg/s/ghc-source-gen/src/GHC/SourceGen/Type.hs:33:1: error: [-Wunused-imports, Werror=unused-imports]
ghc-source-gen>     The import of ‘Language.Haskell.Syntax.Extension’ is redundant
ghc-source-gen>       except perhaps to import instances from ‘Language.Haskell.Syntax.Extension’
ghc-source-gen>     To import instances alone, use: import Language.Haskell.Syntax.Extension()
ghc-source-gen>    |
ghc-source-gen> 33 | import Language.Haskell.Syntax.Extension
ghc-source-gen>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ghc-source-gen> 
ghc-source-gen> /home/greg/s/ghc-source-gen/src/GHC/SourceGen/Pat.hs:22:1: error: [-Wdodgy-imports, Werror=dodgy-imports]
ghc-source-gen>     Module ‘GHC.Hs.Pat’ does not export ‘LHsRecField'’
ghc-source-gen>    |
ghc-source-gen> 22 | import GHC.Hs.Pat hiding (LHsRecField')
ghc-source-gen>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Progress 2/3

Error: [S-7282]
       Stack failed to execute the build plan.

       While executing the build plan, Stack encountered the following errors:

       [S-7011]
       While building package ghc-source-gen-0.4.3.0 (scroll up to its section to see the error) using:
       /home/greg/dotfiles/.stack/setup-exe-cache/x86_64-openbsd/Cabal-simple_sDt42OhJ_3.10.1.0_ghc-9.6.3 --verbose=1 --builddir=.stack-work/dist/x86_64-openbsd/Cabal-3.10.1.0 build lib:ghc-source-gen test:name_test test:pprint_examples test:pprint_test --ghc-options ""
       Process exited with code: ExitFailure 1 

       [S-7011]
       While building package ghc-show-ast-0.0.0 (scroll up to its section to see the error) using:
       /home/greg/dotfiles/.stack/setup-exe-cache/x86_64-openbsd/Cabal-simple_sDt42OhJ_3.10.1.0_ghc-9.6.3 --verbose=1 --builddir=.stack-work/dist/x86_64-openbsd/Cabal-3.10.1.0 build exe:ghc-show-ast --ghc-options ""
       Process exited with code: ExitFailure 1 
Vekhir commented 9 months ago

Is there any progress on merging this PR or otherwise introducing GHC 9.6 support on master? This patch is required for ghc-source-gen to build with GHC 9.6.3 on Arch Linux.

avdv commented 9 months ago

Thank you @blackgnezdo for starting to fix the stack tests. I have added stack configs for GHC 9.4 and 9.6 and also fixed ghc-show-ast.

I have made warnings for unused and dodgy imports non-fatal, this could be cleaned-up if needed.

I also added a CI config on my dev branch, here's the CI run: https://github.com/avdv/ghc-source-gen/actions/runs/7273133498

blackgnezdo commented 9 months ago

@avdv I'd also happily take your CI config commit instead of the existing CI which doesn't seem to work.

I don't see a strong reason to build anywhere outside of ubuntu given the kind of code this project has.

blackgnezdo commented 9 months ago

@jinwoo if you think this looks good, maybe merge it?

jinwoo commented 9 months ago

Thanks!

avdv commented 9 months ago

Thank you for merging!

Regarding CI, it seems it is indeed kicked off and at least jobs for 9.0 and 9.2 were green: https://app.circleci.com/pipelines/github/google/ghc-source-gen/256/workflows/f5ee0484-3828-43e5-9480-c539ab362ba7

If you would like me to add my Github Actions CI config, I'd be happy to create a PR.

jinwoo commented 9 months ago

Thanks, @avdv . @blackgnezdo already added GitHub Actions CI with https://github.com/google/ghc-source-gen/pull/107.