Closed simonmichael closed 3 years ago
Now I see it: "It's important that ghcide is compiled with the same compiler you use to build your projects." Alas!
In this project there's another stack yaml file for GHC 8.6. I hoped this would make ghcide happy, but it didn't:
stack --stack-yaml stack-ghc8.6.yaml exec -- ghcide hledger-lib
I installed another ghcide binary, this time building with GHC 8.8. This solved the problem.
It would be great if the tool could detect and warn about this common mistake.
In this project there's another stack yaml file for GHC 8.6. I hoped this would make ghcide happy, but it didn't [...]
AFAIK the stack
cradle in hie-bios
currently only looks at stack.yaml
and cannot be configured to use another stack configuration, see https://github.com/mpickering/hie-bios/issues/44#issuecomment-532143616.
It would be great if ghc-ide could detect a ghc version mismatch (compile-time vs run-time) and fail early.
How to implement this?
__GLASGOW_HASKELL__
which one can use to record the compile-time version. Hopefully ghc-lib provides something similar?ghc
package, which is built-in and hopefully should be always available. If it turns out that the ghc
package is not always available in the runtime package database, an alternative approach could be to use the version of the base
package. To record it at compile-time, one could invoke the ghc
api via TH.
This is probably generally useful so perhaps worth packaging it on its own if it doesn't already exist.
__GLASGOW_HASKELL__ doesn't include the minor version, unfortunately. Loading any .hi file will trigger the bug though, so perhaps the best check is to early on load an hi file deliberately and see what happens, knowing that its failure is a dodgy runtime vs compiletime.
There is also __GLASGOW_HASKELL_PATCHLEVEL1__
I have uploaded ghc-check to Hackage. Changes to ghcide
in https://github.com/pepeiborra/ghcide/tree/detect-ghc-mismatch, will send PR once haskell/ghcide#460 is merged.
Hi, is there a simple set of instructions to fix this? Sorry for the basic question but I've tried several things (on macOS Catalina) including using ghcup
to switch versions of ghc (instructions here https://gitlab.haskell.org/haskell/ghcup-hs#manual-install) and re-compiling ghcide
. Thanks in advance...
Can you describe the problem @iboy ?
Hi,
macOS 10.15.4
VS code: Version: 1.45.1
ghc: 8.8.3 and 8.6.5
Thanks for your reply. Sorry for the length of this but I include the error messages... and I tried a couple of things to get this to build. I'm sure I'm making a simple mistake somewhere!
I'm following the steps in the ghcide README.md
ghc --version
reports 8.8.3
git clone https://github.com/digital-asset/ghcide.git
cd ghcide
I've tried both cabal and stack:
stack install
Finishes cleanly but - displays this indicating (I think) that ghc 8.6.5 has been used rather than the ghc I set (I tried switching ghc to 8.6.5 seeing if that would work):
Copying from /Users/granian/Develop/Haskell/Editor Support/ghcide/.stack-work/install/x86_64-osx/850bc63fdc2f4b6fa009859c8d6522cb6142cfaffad794062e584882dca14d46/8.6.5/bin/ghcide to /Users/granian/.local/bin/ghcide
Next step:
stack new TestProject simple
cd TestProject
ghcide
Okay. Different error this time: my error is:
Step 6/6: Type checking the files
File: /Users/granian/Develop/Haskell/TestProject/Setup.hs
Hidden: no
Range: 1:7-1:26
Source: not found
Severity: DsError
Message:
Could not load module ‘Distribution.Simple’
It is a member of the hidden package ‘Cabal-3.0.1.0’.
You can run ‘:set -package Cabal’ to expose it.
(Note: this unloads all the modules in the current scope.)
Files that failed:
* /Users/granian/Develop/Haskell/TestProject/Setup.hs
Though I have had the same prim error as in this thread, below - now I'm going through it step by step - I can't replicate it!
ghcide: ghcide: unable to load package ghc-prim-0.5.3
Next: I removed ghcid to start again to try to replicate the error:
\~/.cabal/bin >>> rm ghcid
\~/.cabal/bin >>> rm ghcide
\~/.cabal/bin >>> rm ghcide-test-preprocessor
This time, I ran:
ghcup set ghc 8.6.5
to see if that would match the ghc version indicated in the message above. Then I followed the previous steps and replicated the prim error.
Step 4/6, Cradle 1/1: Loading GHC Session
\> Using main module: 1. Package \`my-first-haskell-project' component my-first-haskell-project:exe:my-first-haskell-project with main-is file: /Users/granian/Develop/Haskell/my-first-haskell-project/src/Main.hs
\> Building all executables for \`my-first-haskell-project' once. After a successful build of all of them, only specified executables will be rebuilt.
\> my-first-haskell-project> configure (exe)
\> Configuring my-first-haskell-project-0.1.0.0...
\> my-first-haskell-project> initial-build-steps (exe)
\> Configuring GHCi with the following packages: my-first-haskell-project
\> /Users/granian/Develop/Haskell/my-first-haskell-project/.stack-work/install/x86_64-osx/92d0321f485b76a4aa342b0aec3819870d3b9a2cb846889dbce103c9d90a6263/8.8.3/pkgdb:/Users/granian/.stack/snapshots/x86_64-osx/92d0321f485b76a4aa342b0aec3819870d3b9a2cb846889dbce103c9d90a6263/8.8.3/pkgdb:/Users/granian/.ghcup/ghc/8.8.3/lib/ghc-8.8.3/package.conf.d
ghcide:
lookupSymbol failed in relocateSection (relocate external)
/Users/granian/.ghcup/ghc/8.8.3/lib/ghc-8.8.3/ghc-prim-0.5.3/HSghc-prim-0.5.3.o: unknown symbol \`_stg_atomicModifyMutVar2zh'
ghcide: ghcide: unable to load package \`ghc-prim-0.5.3'
I've also tried initiating new Haskell projects
stack new my-project
cd my-project
stack setup
then running
ghcide
Same error:
ghcide:
lookupSymbol failed in relocateSection (relocate external)
/Users/granian/.ghcup/ghc/8.8.3/lib/ghc-8.8.3/ghc-prim-0.5.3/HSghc-prim-0.5.3.o: unknown symbol `_stg_atomicModifyMutVar2zh'
ghcide: ghcide: unable to load package `ghc-prim-0.5.3'
This time, thought I switched my ghc version, the ghc lib used seems to be 8.8.3. Maybe I'm not quite getting the architecture of this - I'm exploring Haskell / IDE integration for the first time. Thanks for taking time to reply.
Kind regards, Ian
You are building ghcide with stack install
which doesn't use the ghc installation in your system at all - stack is driven by the resolver specified in the stack.yaml
descriptor and installs a private copy of ghc to build.
You are using stack to build your project, so you need to tell ghcide to use stack to load it - this is done in the hie.yaml
file. See the section "Test ghcide" in the README for more details on how this works. At the end of the day, you need to make sure that the resolver in your project stack.yaml
file is the same or close to the resolver used to build ghcide, otherwise the ghc versions will not match
@iboy did you solve that pb ?
On MacOS 10.13.6
ghcide
with nix nix-env -f "<nixpkgs>" -iA haskellPackages.ghcide
which
gets me a ghcide --version
of ghcide version: 0.1.0 (GHC: 8.8.3)
But upon running ghcide
or stack exec -- ghcide
I get the same
Step 6/6: Type checking the files File: /Users/nrolland/Sync/clones/pickler-combinators/Setup.hs Hidden: no Range: 1:7-1:26 Source: not found Severity: DsError Message: Could not load module ‘Distribution.Simple’ It is a member of the hidden package ‘Cabal-3.0.1.0’. You can run ‘:set -package Cabal’ to expose it. (Note: this unloads all the modules in the current scope.)
ghcide v0.2.0 now tries to detect ghc version mismatches via the ghc-check
package, so this ticket can be closed
Afaik, it does not cover all cases, at least with a specific error message. Maybe the work in progress in hie-bios to detect the ghc used by the project at runtime could improve it?
All the cases that I know of are covered (in HEAD). If you find a missing case, please open a new issue here or in the ghc-check issue tracker.
I built ghcide 0.5.0.0 with GHC 8.6. When I run it so, it fails thus:
I forget and I'm not finding it in the readme just now - is ghcide supposed to work across GHC versions ? Or do you have to use a ghcide compiled with the same GHC as your project ?
https://github.com/digital-asset/ghcide/issues/53 looks similar but the fix there doesn't seem to apply here.