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

Can't build from source with 8.10.7: ‘coreExprToBCOs’ is applied to too few arguments #2860

Closed
maksbotan opened this issue Apr 27, 2022 · 8 comments
Labels
os: nixos type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@maksbotan
Copy link
Contributor

Your environment

Which OS do you use:
macOS 11.6.2
Which LSP client (editor/plugin) do you use:
neovim + coc-nvim
Describe your project (alternative: link to the project):
Not relevant

Steps to reproduce

Basically, I did

  1. Git clone the repo
  2. git checkout 1.7.0.0
  3. cabal new-build exe:haskell-language-server

I have cabal and ghc 8.10.7 in my $PATH, installed from haskell.nix.

$ cabal --version
cabal-install version 3.6.2.0
compiled using version 3.6.2.0 of the Cabal library 
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.7

Expected behaviour

I expect cabal to build me a haskell-language-server exe.

Actual behaviour

Building of ghcide package breaks with this error:

src/Development/IDE/Core/Compile.hs:260:22: error:
    • Couldn't match expected type ‘IO ByteCodeTypes.UnlinkedBCO’
                  with actual type ‘StgSyn.StgRhs -> IO ByteCodeTypes.UnlinkedBCO’
    • Probable cause: ‘coreExprToBCOs’ is applied to too few arguments
      In a stmt of a 'do' block:
        bcos <- coreExprToBCOs
                  hsc_env (icInteractiveModule (hsc_IC hsc_env)) prepd_expr
      In the expression:
        do let dflags = hsc_dflags hsc_env
           simpl_expr <- simplifyExpr dflags hsc_env ds_expr
           let tidy_expr = tidyExpr emptyTidyEnv simpl_expr
           prepd_expr <- corePrepExpr dflags hsc_env tidy_expr
           ....
      In an equation for ‘compile_bco_hook’:
          compile_bco_hook var hsc_env srcspan ds_expr
            = do let dflags = ...
                 simpl_expr <- simplifyExpr dflags hsc_env ds_expr
                 let tidy_expr = ...
                 ....
    |
260 |            ; bcos <- coreExprToBCOs hsc_env
    |                      ^^^^^^^^^^^^^^^^^^^^^^...

src/Development/IDE/Core/Compile.hs:261:63: error:
    • Couldn't match type ‘CoreSyn.Expr CoreSyn.CoreBndr’
                     with ‘GHC.Var’
      Expected type: Id
        Actual type: CoreExpr
    • In the third argument of ‘coreExprToBCOs’, namely ‘prepd_expr’
      In a stmt of a 'do' block:
        bcos <- coreExprToBCOs
                  hsc_env (icInteractiveModule (hsc_IC hsc_env)) prepd_expr
      In the expression:
        do let dflags = hsc_dflags hsc_env
           simpl_expr <- simplifyExpr dflags hsc_env ds_expr
           let tidy_expr = tidyExpr emptyTidyEnv simpl_expr
           prepd_expr <- corePrepExpr dflags hsc_env tidy_expr
           ....
    |
261 |                        (icInteractiveModule (hsc_IC hsc_env)) prepd_expr
    |                                                               ^^^^^^^^^^

Include debug information

I attach cabal.project.freeze generated by cabal new-freeze just in case.

cabal.project.freeze.txt

@maksbotan maksbotan added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Apr 27, 2022
@wz1000
Copy link
Collaborator

wz1000 commented Apr 27, 2022

How did you install GHC? In GHC 8.10.7, coreExprToBCOs has type HscEnv -> Module -> CoreExpr -> IO UnlinkedBCO

Can you start a GHCi session with -package ghc, import ByteCodeGen and then ask for :type coreExprToBCOs?

@amesgen
Copy link
Contributor

amesgen commented Apr 27, 2022

Also hitting this issue with haskell.nix, and indeed, the type is different:

 Λ :t coreExprToBCOs
coreExprToBCOs
  :: HscTypes.HscEnv
     -> Module.Module -> Var.Id -> StgSyn.StgRhs -> IO UnlinkedBCO

So this seems like a haskell.nix issue as it uses slightly patched GHCs. I opened input-output-hk/haskell.nix#1455 to track this.

@wz1000
Copy link
Collaborator

wz1000 commented Apr 27, 2022

It seems like the culprit is haskell.nix: https://github.com/input-output-hk/haskell.nix/blob/a5b74bf002bee3ee41012c8f5e48105150892eee/overlays/patches/ghc/ghc-8.10.5-ubxt.patch

This is a downstream issue since we can't conceivably support all custom distributions of GHC.

@maksbotan
Copy link
Contributor Author

@wz1000

Turns out haskell.nix applies a patch to 8.10 series:
https://github.com/input-output-hk/haskell.nix/blob/master/overlays/patches/ghc/ghc-8.10.5-ubxt.patch

Among other things it has this:

@@ -155,23 +167,25 @@ literals:
 -- Returns: the root BCO for this expression
 coreExprToBCOs :: HscEnv
                -> Module
-               -> CoreExpr
+               -> Id
+               -> StgRhs
                -> IO UnlinkedBCO
-coreExprToBCOs hsc_env this_mod expr
+coreExprToBCOs hsc_env this_mod bndr expr

Do you maybe know corresponding upstream MR? I could not find any reference in haskell.nix repository :/

$ ghci -package ghc
GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help
Loaded package environment from /Users/maksbotan/.ghc/x86_64-darwin-8.10.7/environments/default
Loaded GHCi configuration from /Users/maksbotan/.ghci
λ> import ByteCodeGen
λ> :type coreExprToBCOs
coreExprToBCOs
  :: HscTypes.HscEnv
     -> Module.Module -> Var.Id -> StgSyn.StgRhs -> IO UnlinkedBCO

@maksbotan
Copy link
Contributor Author

@amesgen thanks for reporting this to haskell.nix!

@maksbotan
Copy link
Contributor Author

For anyone interested, I was able to patch HLS source to compile with haskell.nix's compiler. Going to test this setup.

https://gist.github.com/maksbotan/8c7a8f531163c58da9983fbc48d45fff

hamishmack added a commit to input-output-hk/haskell.nix that referenced this issue Apr 28, 2022
This is Maxim Koltsov's work around for building `haskell-language-server` with the haskell.nix compilers that include unboxed tuple patch.

See haskell/haskell-language-server#2860 (comment)
hamishmack added a commit to input-output-hk/haskell.nix that referenced this issue Apr 28, 2022
This is Maxim Koltsov's work around for building `haskell-language-server` with the haskell.nix compilers that include unboxed tuple patch.

See haskell/haskell-language-server#2860 (comment)
@amesgen
Copy link
Contributor

amesgen commented Apr 28, 2022

The patch by @maksbotan is now part of haskell.nix, see input-output-hk/haskell.nix#1457

@wz1000
Copy link
Collaborator

wz1000 commented Sep 7, 2022

Closing as this is a downstream packaging issue.

@wz1000 wz1000 closed this as completed Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os: nixos 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

3 participants