haskell / haskell-ide-engine

The engine for haskell ide-integration. Not an IDE
BSD 3-Clause "New" or "Revised" License
2.38k stars 211 forks source link

Multiple cradle doesn't work #1628

Closed waddlaw closed 4 years ago

waddlaw commented 4 years ago

This repo is not working multi-cradle hie.yaml. Why this code (else if clause) is commented out?

https://github.com/haskell/haskell-ide-engine/blob/4bec07d79cf77c8ee855957d20e315a89f799d75/hie-plugin-api/Haskell/Ide/Engine/Cradle.hs#L98-L120


$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.3 LTS
Release:        18.04
Codename:       bionic

$ ghc -V
The Glorious Glasgow Haskell Compilation System, version 8.6.5

$ hie --version
Version 1.0.0.0, Git revision 4bec07d79cf77c8ee855957d20e315a89f799d75 (dirty) (3745 commits) x86_64 ghc-8.6.5
$ hie-8.6 --version
Version 1.0.0.0, Git revision 4bec07d79cf77c8ee855957d20e315a89f799d75 (dirty) (3745 commits) x86_64 ghc-8.6.5
$ hie-8.8 --version
Version 1.0.0.0, Git revision 4bec07d79cf77c8ee855957d20e315a89f799d75 (dirty) (3745 commits) x86_64 ghc-8.8.2

HIE log:

2020-02-03 10:57:50.131471574 [ThreadId 4] - run entered for hie-wrapper(hie-wrapper) Version 1.0.0.0, Git revision 4bec07d79cf77c8ee855957d20e315a89f799d75 (dirty) (3745 commits) x86_64 ghc-8.6.5
2020-02-03 10:57:50.132142988 [ThreadId 4] - Current directory:/home/guchi/Desktop/hie-bug
2020-02-03 10:57:50.132274236 [ThreadId 4] - Operating system:linux
2020-02-03 10:57:50.132367724 [ThreadId 4] - args:["--lsp"]
2020-02-03 10:57:50.133676137 [ThreadId 4] - Module "/home/guchi/Desktop/hie-bug/File.hs" is loaded by Cradle: Cradle {cradleRootDir = "/home/guchi/Desktop/hie-bug", cradleOptsProg = CradleAction: Multi}
2020-02-03 10:57:50.133879899 [ThreadId 4] - Cradle directory:/home/guchi/Desktop/hie-bug
2020-02-03 10:57:50.134345944 [ThreadId 4] - Executing GHC on path with args: --numeric-version
2020-02-03 10:57:50.175190003 [ThreadId 4] - Project GHC version:8.6.5
2020-02-03 10:57:50.175615723 [ThreadId 4] - hie exe candidates :["hie-8.6.5","hie-8.6","hie"]
2020-02-03 10:57:50.17608307 [ThreadId 4] - found hie exe at:/home/guchi/.local/bin/hie-8.6.5
2020-02-03 10:57:50.176155043 [ThreadId 4] - args:["--lsp"]
2020-02-03 10:57:50.176191159 [ThreadId 4] - launching ....

2020-02-03 10:57:50.178683825 [ThreadId 4] - Run entered for HIE(hie-8.6.5) Version 1.0.0.0, Git revision 4bec07d79cf77c8ee855957d20e315a89f799d75 (dirty) (3745 commits) x86_64 ghc-8.6.5
2020-02-03 10:57:50.179049951 [ThreadId 4] - Operating as a LSP server on stdio
2020-02-03 10:57:50.179118126 [ThreadId 4] - Current directory:/home/guchi/Desktop/hie-bug
2020-02-03 10:57:50.179177941 [ThreadId 4] - Operating system:linux
2020-02-03 10:57:50.179236534 [ThreadId 4] - args:["--lsp"]
2020-02-03 10:57:50.182355549 [ThreadId 4] - Module "/home/guchi/Desktop/hie-bug/File.hs" is loaded by Cradle: Cradle {cradleRootDir = "/home/guchi/Desktop/hie-bug", cradleOptsProg = CradleAction: Multi}
2020-02-03 10:57:50.182619569 [ThreadId 4] - Executing GHC on path with args: --numeric-version
2020-02-03 10:57:50.222837398 [ThreadId 9] - Executing GHC on path with args: --print-libdir
Using hie version: Version 1.0.0.0, Git revision 4bec07d79cf77c8ee855957d20e315a89f799d75 (dirty) (3745 commits) x86_64 ghc-8.6.5
2020-02-03 10:57:50.296241889 [ThreadId 15] - New cradle: /home/guchi/Desktop/hie-bug/src/Lib.hs
2020-02-03 10:57:50.296939184 [ThreadId 15] - Module "/home/guchi/Desktop/hie-bug/src/Lib.hs" is loaded by Cradle: Cradle {cradleRootDir = "/home/guchi/Desktop/hie-bug", cradleOptsProg = CradleAction: Multi}
2020-02-03 10:57:50.297180197 [ThreadId 15] - Found cradle: Cradle {cradleRootDir = "/home/guchi/Desktop/hie-bug", cradleOptsProg = CradleAction: Multi}
Using hoogle db at: /home/guchi/.hoogle/default-haskell-5.0.17.hoo
2020-02-03 10:57:50.490966299 [ThreadId 23] - Stack has not been tested with GHC versions above 8.6, and using 8.8.1, this may fail
2020-02-03 10:57:50.57400507 [ThreadId 23] - Stack has not been tested with Cabal versions above 2.4, but version 3.0.0.0 was found, this may fail
2020-02-03 10:57:50.818555628 [ThreadId 23] - Building all executables for `hie-bug' once. After a successful build of all of them, only specified executables will be rebuilt.
2020-02-03 10:57:50.819614749 [ThreadId 23] - hie-bug> initial-build-steps (lib + exe)
2020-02-03 10:57:50.952289738 [ThreadId 23] - Configuring GHCi with the following packages: hie-bug
2020-02-03 10:57:51.186865319 [ThreadId 29] - Stack has not been tested with GHC versions above 8.6, and using 8.8.1, this may fail
2020-02-03 10:57:51.264658225 [ThreadId 29] - Stack has not been tested with Cabal versions above 2.4, but version 3.0.0.0 was found, this may fail
2020-02-03 10:57:51.423837498 [ThreadId 29] - Stack has not been tested with GHC versions above 8.6, and using 8.8.1, this may fail
2020-02-03 10:57:51.499506999 [ThreadId 29] - Stack has not been tested with Cabal versions above 2.4, but version 3.0.0.0 was found, this may fail
2020-02-03 10:57:51.510115456 [ThreadId 31] - /home/guchi/Desktop/hie-bug/.stack-work/install/x86_64-linux/318e0bb48b613155cb7f0b3fb815b41d8e85cbedd0879e4e4205145a2d6d65eb/8.8.1/pkgdb:/home/guchi/.stack/snapshots/x86_64-linux/318e0bb48b613155cb7f0b3fb815b41d8e85cbedd0879e4e4205145a2d6d65eb/8.8.1/pkgdb:/home/guchi/.stack/programs/x86_64-linux/ghc-8.8.1/lib/ghc-8.8.1/package.conf.d
hie-8.6.5: /home/guchi/.stack/programs/x86_64-linux/ghc-8.8.1/lib/ghc-8.8.1/ghc-prim-0.5.3/HSghc-prim-0.5.3.o: unknown symbol `stg_atomicModifyMutVar2zh'
2020-02-03 10:57:51.583824091 [ThreadId 20] - Ghc error on cradle initialisation: "unable to load package `ghc-prim-0.5.3'"
2020-02-03 10:57:51.584002176 [ThreadId 15] - ghcDispatcher:Got error for a request: IdeError {ideCode = OtherError, ideMessage = "\"unable to load package `ghc-prim-0.5.3'\"", ideInfo = Null} with mid: Nothing
2020-02-03 10:57:51.584249299 [ThreadId 15] - New cradle: /home/guchi/Desktop/hie-bug/src/Lib.hs
2020-02-03 10:57:51.584828533 [ThreadId 15] - Module "/home/guchi/Desktop/hie-bug/src/Lib.hs" is loaded by Cradle: Cradle {cradleRootDir = "/home/guchi/Desktop/hie-bug", cradleOptsProg = CradleAction: Multi}
2020-02-03 10:57:51.585112451 [ThreadId 15] - Found cradle: Cradle {cradleRootDir = "/home/guchi/Desktop/hie-bug", cradleOptsProg = CradleAction: Multi}
2020-02-03 10:57:51.780198746 [ThreadId 41] - Stack has not been tested with GHC versions above 8.6, and using 8.8.1, this may fail
2020-02-03 10:57:51.86717794 [ThreadId 41] - Stack has not been tested with Cabal versions above 2.4, but version 3.0.0.0 was found, this may fail
2020-02-03 10:57:52.115602904 [ThreadId 41] - Building all executables for `hie-bug' once. After a successful build of all of them, only specified executables will be rebuilt.
2020-02-03 10:57:52.116633448 [ThreadId 41] - hie-bug> initial-build-steps (lib + exe)
2020-02-03 10:57:52.251543906 [ThreadId 41] - Configuring GHCi with the following packages: hie-bug
2020-02-03 10:57:52.484931905 [ThreadId 49] - Stack has not been tested with GHC versions above 8.6, and using 8.8.1, this may fail
2020-02-03 10:57:52.563125192 [ThreadId 49] - Stack has not been tested with Cabal versions above 2.4, but version 3.0.0.0 was found, this may fail
2020-02-03 10:57:52.719395487 [ThreadId 49] - Stack has not been tested with GHC versions above 8.6, and using 8.8.1, this may fail
2020-02-03 10:57:52.794505179 [ThreadId 49] - Stack has not been tested with Cabal versions above 2.4, but version 3.0.0.0 was found, this may fail
2020-02-03 10:57:52.804968797 [ThreadId 48] - /home/guchi/Desktop/hie-bug/.stack-work/install/x86_64-linux/318e0bb48b613155cb7f0b3fb815b41d8e85cbedd0879e4e4205145a2d6d65eb/8.8.1/pkgdb:/home/guchi/.stack/snapshots/x86_64-linux/318e0bb48b613155cb7f0b3fb815b41d8e85cbedd0879e4e4205145a2d6d65eb/8.8.1/pkgdb:/home/guchi/.stack/programs/x86_64-linux/ghc-8.8.1/lib/ghc-8.8.1/package.conf.d
2020-02-03 10:57:52.849710432 [ThreadId 38] - Ghc error on cradle initialisation: "panic! (the 'impossible' happened)\n  (GHC version 8.6.5 for x86_64-unknown-linux):\n\tDynamic linker not initialised\n\nPlease report this as a GHC bug:  http://www.haskell.org/ghc/reportabug\n"
2020-02-03 10:57:52.849886369 [ThreadId 15] - ghcDispatcher:Got error for a request: IdeError {ideCode = OtherError, ideMessage = "\"panic! (the 'impossible' happened)\\n  (GHC version 8.6.5 for x86_64-unknown-linux):\\n\\tDynamic linker not initialised\\n\\nPlease report this as a GHC bug:  http://www.haskell.org/ghc/reportabug\\n\"", ideInfo = Null} with mid: Nothing
fendor commented 4 years ago

Well, there is a comment explaining it:

     -- The command `cabal v2-exec -v0 ghc` only works if the project has been 
     -- built already. 
     -- This command must work though before the project is build. 
     -- Therefore, fallback to "ghc" on the path. 

So, this is a stack multi-cradle? What is the content of your hie.yaml? Or your stack.yaml? It seems that the project does not agree on the ghc version to use, see 8.8.1 everywhere, but the hie version has been compiled with 8.6.5

waddlaw commented 4 years ago

Thank you for quick reply! My project specifies -w ghc-8.8.1 in thecabal.project file. However, the version of ghc installed on the system is 8.6.5. Therefore, it seems that there is a mismatch in ghc version detection.

Changing the system ghc version to 8.8.1 will fix it.

The content of the hie.yaml file:

cradle:
  multi:
    # stack
    - path: "./app/Main.hs"
      config: { cradle: {stack: {component: "hie-bug:exe:hie-bug-exe"}} }
    - path: "./src"
      config: { cradle: {stack: {component: "hie-bug:lib"}} }
    - path : "./test"
      config: { cradle: {stack: {component: "hie-bug:test:hie-bug-test"}} }

    # cabal
    - path: "./app/Main.hs"
      config: { cradle: {cabal: {component: "hie-bug:hie-bug-exe"}} }
    - path: "./src"
      config: { cradle: {cabal: {component: "lib:hie-bug"}} }
    - path : "./test"
      config: { cradle: {cabal: {component: "hie-bug:hie-bug-test"}} }

and stack.yaml

resolver: nightly-2020-01-19
fendor commented 4 years ago

Ok, yeah, so, this is a missing feature. If you only specified stack cradles, e.g. comment out the cabal cradle paths, then the right ghc version should be detected, too. Would you mind checking it?

So, the bug is that we are not honouring the cabal -w flag. I think there is an issue for that already.

waddlaw commented 4 years ago

If you only specified stack cradles, e.g. comment out the cabal cradle paths, then the right ghc version should be detected, too. Would you mind checking it?

It worked correctly! Thank you. But, get this warning:

Screen Shot 2020-02-04 at 11 27 34

hie.yaml is this:

cradle:
  multi:
    # stack
    - path: "./app/Main.hs"
      config: { cradle: {stack: {component: "hie-bug:exe:hie-bug-exe"}} }
    - path: "./src"
      config: { cradle: {stack: {component: "hie-bug:lib"}} }
    - path : "./test"
      config: { cradle: {stack: {component: "hie-bug:test:hie-bug-test"}} }

    # cabal
    # - path: "./app/Main.hs"
    #   config: { cradle: {cabal: {component: "hie-bug:hie-bug-exe"}} }
    # - path: "./src"
    #   config: { cradle: {cabal: {component: "lib:hie-bug"}} }
    # - path : "./test"
    #   config: { cradle: {cabal: {component: "hie-bug:hie-bug-test"}} }

The command cabal v2-exec -v0 ghc only works if the project has been built already. This command must work though before the project is build.

How about running after creating the dist-newstyle/tmp directory?

$ ghc -V
The Glorious Glasgow Haskell Compilation System, version 8.6.5

$ mkdir dist-newstyle/tmp
$ cabal v2-exec -v0 ghc -- -V
The Glorious Glasgow Haskell Compilation System, version 8.8.1
waddlaw commented 4 years ago

Can I ignore this warning?

fendor commented 4 years ago

With stack, you should not produce this warning, afaict. What is your stack.yaml?

waddlaw commented 4 years ago

stack.yaml has only one line.

resolver: nightly-2020-01-19
fendor commented 4 years ago

What are your logs if your hie.yaml only looks like:

cradle:
  stack:
    - path: "./app/Main.hs"
      config: { cradle: {stack: {component: "hie-bug:exe:hie-bug-exe"}} }
    - path: "./src"
      config: { cradle: {stack: {component: "hie-bug:lib"}} }
    - path : "./test"
      config: { cradle: {stack: {component: "hie-bug:test:hie-bug-test"}} }
waddlaw commented 4 years ago

No more warnings when upgrading hie version. hie.yaml has not changed anything. The current HIE version is as follows.

$ hie --version
Version 1.1, Git revision 7283ae2eae069d15a226ff0d458007db59a00f84 (dirty) (3770 commits) x86_64 ghc-8.8.2
$ hie-8.8 --version
Version 1.1, Git revision 7283ae2eae069d15a226ff0d458007db59a00f84 (dirty) (3770 commits) x86_64 ghc-8.8.2
$ hie-8.6 --version
Version 1.0.0.0, Git revision 4bec07d79cf77c8ee855957d20e315a89f799d75 (dirty) (3745 commits) x86_64 ghc-8.6.5

@fendor. Thank you for teaching me carefully.