Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HLS fails to compile where "stack repl" succeeds, even with hie.yaml: cradle: stack: #4484

Open
kenton-waters opened this issue Jan 21, 2025 · 0 comments
Labels
status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@kenton-waters
Copy link

Summary/TLDR

I am trying to get a minimal example of LiquidHaskell working with HLS, and I'm running into the following issue:

The haskell-language-server-wrapper command produces an inappropriate compilation error:

Unknown type constructor `Pos`
    matchTyCon: Pos

The stack repl command, on the other hand, compiles successfully without producing the error (this is the correct behavior, as the code itself is correct).

HLS produces the error despite the project containing a hie.yaml file with these contents:

cradle:
  stack:

My understanding was that this was supposed to make HLS build "the same way" that Stack does. Why might HLS build differently than Stack, even when the hie.yaml file is present?

Your environment

Which OS do you use?

Arch Linux

Which version of GHC do you use and how did you install it?

GHC 9.8.1 from ghcup

How is your project built (alternative: link to the project)?

I am building this project: https://github.com/ucsd-progsys/lh-plugin-demo.git via Stack. Please see "Steps to reproduce" for more details.

Which LSP client (editor/plugin) do you use?

VSCode + vscode-haskell

Which version of HLS do you use and how did you install it?

HLS 2.6.0.0 from ghcup

Have you configured HLS in any way (especially: a hie.yaml file)?

hie.yaml file with the following contents:

cradle:
  stack:

Steps to reproduce

Install the following via ghcup:

  • HLS 2.6.0.0
  • GHC 9.8.1
  • Stack 3.1.1
  • cabal 3.12.1

Then: git clone https://github.com/ucsd-progsys/lh-plugin-demo.git

Replace the contents of the stack.yaml file with the following:

resolver: nightly-2024-01-26

system-ghc: true

packages:
  - .
extra-deps:
  - rest-rewrite-0.4.3
  - smtlib-backends-0.3
  - smtlib-backends-process-0.3
  - store-0.7.18
  - store-core-0.4.4.7
  - liquidhaskell-0.9.8.1
  - liquidhaskell-boot-0.9.8.1
  - liquid-fixpoint-0.9.6.3
  - liquid-prelude-0.9.2.8.1@rev:1
  - liquid-vector-0.13.1.0.1

nix:
  packages: [cacert, git, hostname, z3]

Create a top-level hie.yaml file with the following contents:

cradle:
  stack:

Replace the contents of src/Demo/Client.hs with the following:

{-# OPTIONS_GHC -fplugin=LiquidHaskell #-}
module Demo.Client where
import Demo.Lib

{-@ posId :: Pos -> Pos @-}
posId :: Int -> Int
posId = id

At this point,

stack build compiles with no errors.

stack ghci compiles with no errors.

stack repl compiles with no errors.

haskell-language-server-wrapper produces a compilation error:

Unknown type constructor `Pos`
    matchTyCon: Pos

Why might HLS build differently than Stack, even when the hie.yaml file is present? Thank you in advance for your help!

Expected behaviour

The haskell-language-server-wrapper command should compile successfully, without producing compilation errors, just like the stack build command already does.

Actual behaviour

haskell-language-server-wrapper produces a compilation error:

Unknown type constructor `Pos`
    matchTyCon: Pos

This compilation error is incorrect because the refinement type Pos should be successfully imported from the module Demo.Lib in which it is defined.

Debug information

I was able to recreate this issue with ghcid.

The command ghcid fails to compile with the same error that HLS is producing.

The command ghcid "--command=stack ghci" compiles with no errors, giving the All good message. This does not immediately help me resolve the issue with HLS, though.

Output of haskell-language-server-wrapper --debug:

Found "/home/kenton/repos/haskell/issue/lh-plugin-demo/hie.yaml" for "/home/kenton/repos/haskell/issue/lh-plugin-demo/a"
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 2.6.0.0 x86_64 ghc-9.2.8
Current directory: /home/kenton/repos/haskell/issue/lh-plugin-demo
Operating system: linux
Arguments: ["--debug"]
Cradle directory: /home/kenton/repos/haskell/issue/lh-plugin-demo
Cradle type: Stack

Tool versions found on the $PATH
cabal:          3.12.1.0
stack:          3.1.1
ghc:            9.8.1


Consulting the cradle to get project GHC version...
2025-01-21T02:40:22.851615Z | Debug | stack setup --silent
2025-01-21T02:40:23.237797Z | Debug | stack exec ghc -- --numeric-version
Project GHC version: 9.8.1
haskell-language-server exe candidates: ["haskell-language-server-9.8.1","haskell-language-server"]
Launching haskell-language-server exe at:/home/kenton/.ghcup/bin/haskell-language-server-9.8.1
2025-01-21T02:40:23.565090Z | Debug | stack setup --silent
2025-01-21T02:40:24.060913Z | Debug | stack exec ghc -- -v0 -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
2025-01-21T02:40:24.401537Z | Debug | stack setup --silent
2025-01-21T02:40:24.793602Z | Debug | stack exec ghc -- --print-libdir
2025-01-21T02:40:27.624203Z | Info | haskell-language-server version: 2.6.0.0 (GHC: 9.8.1) (PATH: /home/kenton/.ghcup/hls/2.6.0.0/lib/haskell-language-server-2.6.0.0/bin/haskell-language-server-9.8.1)
2025-01-21T02:40:27.626095Z | Info | Directory: /home/kenton/repos/haskell/issue/lh-plugin-demo
2025-01-21T02:40:27.626778Z | Info | Logging heap statistics every 60.00s
 ghcide setup tester in /home/kenton/repos/haskell/issue/lh-plugin-demo.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Step 1/4: Finding files to test in /home/kenton/repos/haskell/issue/lh-plugin-demo
Found 3 files

Step 2/4: Looking for hie.yaml files that control setup
Found 1 cradle
  (/home/kenton/repos/haskell/issue/lh-plugin-demo/hie.yaml)

Step 3/4: Initializing the IDE
2025-01-21T02:40:27.635329Z | Debug | Initializing exports map from hiedb
2025-01-21T02:40:27.635912Z | Debug | Shake session initialized

Step 4/4: Type checking the files
2025-01-21T02:40:27.638234Z | Debug | Done initializing exports map from hiedb. Size: 17
2025-01-21T02:40:27.639199Z | Info | Cradle path: src/Demo/Lib.hs
2025-01-21T02:40:27.640097Z | Debug | Cradle: Cradle{ cradleRootDir = "/home/kenton/repos/haskell/issue/lh-plugin-demo", cradleOptsProg = CradleAction: Stack}
2025-01-21T02:40:27.640220Z | Info | invoking build tool to determine build flags (this may take some time depending on the cache)
2025-01-21T02:40:27.641303Z | Info | stack repl --no-nix-pure --with-ghc /home/kenton/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36
  Environment Variables
    HIE_BIOS_OUTPUT: /tmp/HIE_BIOS_OUTPUT2850-0
2025-01-21T02:40:30.554601Z | Debug | Configuring GHCi with the following packages: lh-plugin-demo.
2025-01-21T02:40:30.569392Z | Info | stack path --ghc-package-path
  Environment Variables
    HIE_BIOS_OUTPUT: /tmp/HIE_BIOS_OUTPUT2850-1
2025-01-21T02:40:30.903579Z | Debug | /home/kenton/repos/haskell/issue/lh-plugin-demo/.stack-work/install/x86_64-linux/dadb316ace9de2488db917156d882ca277926bfd125a4e2ec70e0958a1962e30/9.8.1/pkgdb:/home/kenton/.stack/snapshots/x86_64-linux/dadb316ace9de2488db917156d882ca277926bfd125a4e2ec70e0958a1962e30/9.8.1/pkgdb:/home/kenton/.ghcup/ghc/9.8.1/lib/ghc-9.8.1/lib/package.conf.d
2025-01-21T02:40:31.222491Z | Debug | stack setup --silent
2025-01-21T02:40:31.616170Z | Debug | stack exec ghc -- --print-libdir
2025-01-21T02:40:31.616321Z | Debug | Session loading result: Right (ComponentOptions {componentOptions = ["-i","-odir=/home/kenton/repos/haskell/issue/lh-plugin-demo/.stack-work/odir","-hidir=/home/kenton/repos/haskell/issue/lh-plugin-demo/.stack-work/odir","-hide-all-packages","-XHaskell2010","-i/home/kenton/repos/haskell/issue/lh-plugin-demo/.stack-work/dist/x86_64-linux/ghc-9.8.1/build","-i/home/kenton/repos/haskell/issue/lh-plugin-demo/src","-i/home/kenton/repos/haskell/issue/lh-plugin-demo/.stack-work/dist/x86_64-linux/ghc-9.8.1/build/autogen","-i/home/kenton/repos/haskell/issue/lh-plugin-demo/.stack-work/dist/x86_64-linux/ghc-9.8.1/build/global-autogen","-stubdir=/home/kenton/repos/haskell/issue/lh-plugin-demo/.stack-work/dist/x86_64-linux/ghc-9.8.1/build","-package-id=liquid-prelude-0.9.2.8.1-BQWu5CWb979FOXNsYFOZTS","-package-id=liquid-vector-0.13.1.0.1-LAZqfiLyRNbQzeDvX2znO","-package-id=liquidhaskell-0.9.8.1-3j1pmEZ7aitJz0n2ZF5jz0","-package-id=base-4.19.0.0-c1f2","-package-id=containers-0.6.8-3ad8","-package-id=vector-0.13.1.0-KLRdDSd3uHFIQ31PGs0nmd","-optP-include","-optP/home/kenton/repos/haskell/issue/lh-plugin-demo/.stack-work/ghci/907932ae/cabal_macros.h","-ghci-script=/home/kenton/.cache/stack/ghci-script/5bc6b1db/ghci-script","-package-db","/home/kenton/repos/haskell/issue/lh-plugin-demo/.stack-work/install/x86_64-linux/dadb316ace9de2488db917156d882ca277926bfd125a4e2ec70e0958a1962e30/9.8.1/pkgdb","-package-db","/home/kenton/.stack/snapshots/x86_64-linux/dadb316ace9de2488db917156d882ca277926bfd125a4e2ec70e0958a1962e30/9.8.1/pkgdb","-package-db","/home/kenton/.ghcup/ghc/9.8.1/lib/ghc-9.8.1/lib/package.conf.d"], componentRoot = "/home/kenton/repos/haskell/issue/lh-plugin-demo", componentDependencies = ["lh-plugin-demo.cabal","package.yaml","stack.yaml"]},"/home/kenton/.ghcup/ghc/9.8.1/lib/ghc-9.8.1/lib")
2025-01-21T02:40:31.666115Z | Info | Interface files cache directory: /home/kenton/.cache/ghcide/main-e051576f66141c4899a23e1b38102cc966e0f9ee-e051576f66141c4899a23e1b38102cc966e0f9ee
2025-01-21T02:40:31.675830Z | Info | Making new HscEnv. In-place unit ids: [ main-e051576f66141c4899a23e1b38102cc966e0f9ee ]
2025-01-21T02:40:31.725700Z | Debug | New component cache HscEnvEq: (([],Just HscEnvEq 4),fromList [("/home/kenton/repos/haskell/issue/lh-plugin-demo/hie.yaml",Just 2025-01-20 23:21:16.25044742 UTC),("lh-plugin-demo.cabal",Just 2025-01-20 22:49:26.91252873 UTC),("package.yaml",Nothing),("stack.yaml",Just 2025-01-20 22:57:22.598735881 UTC)])
2025-01-21T02:40:31.960833Z | Debug | Known files updated:
  fromList [(TargetModule (ModuleName "Demo.Client"),fromList ["/home/kenton/repos/haskell/issue/lh-plugin-demo/src/Demo/Client.hs"]),(TargetFile NormalizedFilePath "/home/kenton/repos/haskell/issue/lh-plugin-demo/src/Demo/Lib.hs",fromList ["/home/kenton/repos/haskell/issue/lh-plugin-demo/src/Demo/Lib.hs"]),(TargetModule (ModuleName "Demo.Erase"),fromList ["/home/kenton/repos/haskell/issue/lh-plugin-demo/src/Demo/Erase.hs"]),(TargetModule (ModuleName "Demo.Lib"),fromList ["/home/kenton/repos/haskell/issue/lh-plugin-demo/src/Demo/Lib.hs"])]
2025-01-21T02:40:31.961192Z | Debug | Finished build session
AsyncCancelled
2025-01-21T02:40:31.961282Z | Debug | Restarting build session due to new component
Action Queue: [User TypeCheck]
Keys: [GhcSessionIO; , GetKnownTargets; ]
Aborting previous build session took 0.00s 

**** LIQUID: SAFE (47 constraints checked) *************************************
2025-01-21T02:40:35.316418Z | Info | updateFileDiagnostics published different from new diagnostics - file diagnostics: File:     /home/kenton/repos/haskell/issue/lh-plugin-demo/src/Demo/Client.hs
Hidden:   no
Range:    5:14-5:17
Source:   typecheck
Severity: DiagnosticSeverity_Error
Message:  Unknown type constructor `Pos`matchTyCon: Pos

**** LIQUID: SAFE (26 constraints checked) *************************************
2025-01-21T02:40:35.529484Z | Debug | Finished: User TypeCheck Took: 3.57s
2025-01-21T02:40:35.541030Z | Debug | Finished: GetHie Took: 0.01s
2025-01-21T02:40:35.551181Z | Debug | Finished: GenerateCore Took: 0.01s
Files that failed:
 * /home/kenton/repos/haskell/issue/lh-plugin-demo/src/Demo/Client.hs

Completed (2 files worked, 1 file failed)
@kenton-waters kenton-waters added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

No branches or pull requests

1 participant