tweag / rules_haskell

Haskell rules for Bazel.
https://haskell.build
Apache License 2.0
261 stars 79 forks source link

Haskell Language Server failure when rule have same package name #1482

Open guibou opened 3 years ago

guibou commented 3 years ago

Describe the bug

The haskell language server will fail on a file if that file is part of a package which depends on two package with the same package name, but different package id.

For example, we have a file File.hs is part of an haskell_library //lib which depends on //foo:time and //biz:time.

//foo:time and //biz:time are two different (Haskell) packages, with the same Haskell package name (i.e. time) but different package id (eg time-1234 and time-5678).

In this context, the language server is not able to "work" on File.hs and complains about:

Message: 
  Could not load module ‘Data.Time.Clock’
  It is a member of the hidden package ‘time-1.9.3’.
  You can run ‘:set -package time’ to expose it.
  (Note: this unloads all the modules in the current scope.)

To Reproduce

Well, I may come back later on this issue to provide a proper reproduction. In the meantime:

Not that this error message does not appear on other modules in my codebase as long as they do not depend at the same time on two packages with the same package name (here time).

Expected behavior

It should not fail ;)

Environment

Additional context

402 and associated are linked. The problem is that GHC does have a bug that, in presence of the same package name, GHC will pick the latest in the command line (even if -package-id is used) unless -hide-all-packages is part of the command line.

I fixed locally the problem with the following change in my .hie-bios file:

diff --git a/.hie-bios b/.hie-bios
index cfddda027..af7d0e0db 100755
--- a/.hie-bios
+++ b/.hie-bios
@@ -1,6 +1,8 @@
 #!/usr/bin/env bash
 set -euo pipefail
 kazel build //hls:hls@repl --output_groups=hie_bios
-cat bazel-bin/hls/hls@repl@hie-bios >"$HIE_BIOS_OUTPUT"
+
+echo "-hide-all-packages" > "$HIE_BIOS_OUTPUT"
+cat bazel-bin/hls/hls@repl@hie-bios >> "$HIE_BIOS_OUTPUT"
 # Make warnings non-fatal
 echo -Wwarn >>"$HIE_BIOS_OUTPUT"
guibou commented 3 years ago

Haha, I just found that:

https://gitlab.haskell.org/ghc/ghc/-/blob/master/compiler/GHC/Unit/State.hs#L860

Not sure we had seen it previously, but it explains the reasons behind -hide-all-packages.

guibou commented 3 years ago

I hit this issue again today on a new codebase.