Home > Back-end >  Why does a project created with stack new @ GHC 9.0.2 crash the language server?
Why does a project created with stack new @ GHC 9.0.2 crash the language server?

Time:07-29

I am completely new to haskell. From what I've gathered so far about the tool chain, cabal and Stack are competing build/package management tools. The answers to this question were quite informative.

I was happy to learn that haskell has a mature language server available, but in going to test it out on a project created via stack new, confused to find that the server immediately crashed. Here are some relevant log lines:

2022-07-22 17:09:54.8270000 [client] INFO Executing 'ghcup --no-verbose whereis ghc 9.0.2' in cwd '/home/randy'
2022-07-22 17:09:54.8440000 [client] ERROR Error executing 'ghcup --no-verbose whereis ghc 9.0.2' with error code 30
2022-07-22 17:09:54.8440000 [client] ERROR stderr: [1m[ Error ][0m The version 9.0.2 of the tool ghc is not installed.
2022-07-22 17:09:59.1650000 [client] INFO User accepted download for ghc-9.0.2.

I installed haskell via GHCup, which installed GHC 8.10.7 and Stack 2.7.5. However, the generated stack.yaml references the following resolver url, which specifies GHC 9.0.2: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/16.yaml.

Once the language server starts, it crashes repeatedly because of ABI mismatches:

[0;31mGHC ABIs don't match![0m
[0;31m[0m
[0;31mExpected: Cabal-3.4.1.0:bd8a150942e263abdddf4556ba717d44 array-0.5.4.0:6e4d88804dfcdc3d22d4fbacc50bc1d6 ...
[0;31mGot:      Cabal-3.4.1.0:ab74f2c3161b496273c112bc304128c5 array-0.5.4.0:60b03bb14f2fb672c7d45b226c353ec1 ...

I also tried creating a new project with cabal init --interactive. That project seems to be satisfied with the installed GHC version, and the language server works as expected.

My best guess at this point is that the GHC version difference in the Stack project is to blame, but I don't know why it happens or how to fix it.

For reference, the installed HLS is v1.7.0.0, and cabal is at v3.6.2.0.

CodePudding user response:

Thanks for @sjakobi's help, I learned from this issue that GHC 9.0.2 on linux and 9.2.2 on windows initially had missing profiling libs and were as such replaced with new bindists, causing their ABIs to change. However, stack still uses the old bindist without profiling libs, so HLS used on a project created with stack crashes due to the mismatch.

It turns out this is covered in the FAQ of the vscode-haskell docs. Quoting from there:

Force it to install the fixed bindist (that includes profiling libs) by adding this to your stack.yaml (depending on your platform):

setup-info:   ghc:
    linux64-tinfo6:
      9.0.2:
        url: "https://downloads.haskell.org/ghc/9.0.2/ghc-9.0.2a-x86_64-fedora27-linux.tar.xz"

Alternatively let GHCup install the correct bindist and then set system-ghc: true in your stack.yaml.

Now make sure to remove cached/installed libraries to avoid getting segfaults at runtime.

  • Related