Description
After upgrading to GHC-9.4.5, we've been noticing a lot more of the -package ... is hidden
errors in HLS with a stack multi-cradle.
Initially I thought this was merely #366. But after further testing it's clear that this is caused by something else. #366 is caused by stack repl
failing to pass the correct arguments when components aren't already built. But this error also happens when they have successfully built.
I then compared the dynflags that cabal
and stack
produce for the same project. I noticed that cabal
passed -this-unit-id
while stack
did not. Adding -this-unit-id <package-name>
to ghc-options for each package made the new problem go away.
So, my theory is that because stack repl
doesn't pass -this-unit-id
to GHC, something with GHC's new MHU breaks, causing only the dependencies of one package to be exposed in HLS's GHC API session.
My impression is that this issue will occur when using HLS, with stack, GHC 9.4, and any session with multiple components loaded.
I've created a somewhat minimal reproducer below.
Your environment
Which OS do you use? NixOS
Which version of GHC do you use and how did you install it? GHC 9.4.5 using nix
How is your project built (alternative: link to the project)? stack
Which LSP client (editor/plugin) do you use? emacs+lsp-mode
Which version of HLS do you use and how did you install it? 1.10.0 and 2.0.0 (built with nix)
Have you configured HLS in any way (especially: a hie.yaml
file)? yes, hie.yaml generated by gen-hie
Steps to reproduce
I've created a somewhat minimal reproducer: https://github.com/TeofilC/hls-repro-1
It features two packages that have different dependencies.
When opening both in a single HLS session with stack, HLS fails with a -package is hidden
error.
git clone https://github.com/TeofilC/hls-repro-1.git
cd hls-repro-1
nix develop
(if you use nix or get stack/hls some other way)stack build
haskell-language-server -d pack-a/src/Lib1.hs pack-b/src/Lib2.hs
If using nix make sure you have the following in your .stack/config:
nix:
enable: false
system-ghc: true
Expected behaviour
HLS should be able to load these modules and can do if we use cabal instead.
Actual behaviour
It fails:
Message:
Could not load module ‘Data.These’
It is a member of the hidden package ‘these-1.2’.
You can run ‘:set -package these’ to expose it.
(Note: this unloads all the modules in the current scope.)
2023-05-28T15:11:31.379037Z | Debug | Finished: User TypeCheck Took: 0.03s
2023-05-28T15:11:31.379893Z | Debug | Finished: GetHie Took: 0.00s
2023-05-28T15:11:31.380154Z | Debug | LOOKUP PERSISTENT FOR: GhcSessionDeps
2023-05-28T15:11:31.380246Z | Debug | Finished: GenerateCore Took: 0.00s
Files that failed:
* ./pack-b/src/Lib2.hs
Completed (1 file worked, 1 file failed)