Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

[#518] Build ghcide with GHC 8.10.1 #519

Merged
merged 15 commits into from
May 11, 2020
Merged

[#518] Build ghcide with GHC 8.10.1 #519

merged 15 commits into from
May 11, 2020

Conversation

chshersh
Copy link
Member

@chshersh chshersh commented Apr 2, 2020

Resolves #518

I was able to implement a small patch that allows ghcide to build with GHC 8.10. A couple of tests are failing, though. Any feedback is appreciated!

@digitalasset-cla
Copy link

digitalasset-cla commented Apr 2, 2020

CLA assistant check
All committers have signed the CLA.

@@ -144,7 +144,7 @@ library
Development.IDE.Plugin.CodeAction.RuleTypes
Development.IDE.Plugin.Completions.Logic
Development.IDE.Plugin.Completions.Types
if impl(ghc > 8.7) || flag(ghc-lib)
if (impl(ghc > 8.7) && impl(ghc < 8.10)) || flag(ghc-lib)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is correct, then why do we need the file in tree for 8.8 as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains the implementation of the mkHieFile function. This function is present in GHC 8.10. And the implementation for GHC-8.8 is based on HIE files from GHC, where the implementation of this function for GHC 8.6 is based on ghcide own reimplementation of HIE files. So there are 3 cases for this function.

Copy link
Collaborator

@pepeiborra pepeiborra Apr 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version of mkHieFile in GHC 8.8 was unsuitable for ghcide, so we inlined the implementation locally to fix it. After that, @mpickering yourself propagated the fix upstream, which is the reason it happily does not need to be inlined when building against GHC 8.10

EDIT: oh no, it looks like the fix didn't make it into 8.10, and we still need to use the local version. I guess that complicates things a bit ...

let tc_binds = tcg_binds ts
(asts', arr) <- getCompressedAsts tc_binds rs
let Just src_file = ml_hs_file $ ms_location ms
src <- liftIO $ BS.readFile src_file
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is how the mkHieFile function is implemented in GHC 8.10. This function is called only once in the whole codebase and empty string "" is passed as an argument to it instead of src. Maybe this was done for some performance/memory reasons, but I made the implementation consistent with GHC 8.10 to have fewer surprises.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is unsuitable for ghcide where files opened in the editor live in a virtual file system, and was the reason that we had to inline this module and change the implementation of mkHieFile. Please revert :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of copying this file is to remove this part of the implementation if I remember correctly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pepeiborra Thanks for the detailed explanation. This change is reverted. The HieAst module for ghc-8.8 has no changes now.

@chshersh
Copy link
Member Author

chshersh commented Apr 4, 2020

Thanks, @pepeiborra for the patch! I guess now the build is failing due to HLint warnings in the new file.

@chshersh
Copy link
Member Author

chshersh commented Apr 7, 2020

CI for GHC 8.10 fails due to the test failure. The following test fails, don't know how to fix it:

  plugins:                                                       FAIL (1.49s)
    test/src/Development/IDE/Test.hs:39:
    Could not find (DsError,(8,14),"Variable not in scope: c") in List [Diagnostic {_range = Range {_start = Position {_line = 0, _character = 0}, _end = Position {_line = 0, _character = 0}}, _severity = Just DsError, _code = Nothing, _source = Just "typecheck", _message = "/tmp/extra-dir-78866602889079/Testing.hs:1:1: error:\n    Bad interface file: /home/vsts/.stack/snapshots/x86_64-linux/0d09385e35771f64a4c4bf9b92b8b30fbc8ce487126f21b5edfae99a26a1d108/8.10.1/lib/x86_64-linux-ghc-8.10.1/ghc-typelits-knownnat-0.7.2-DCI9V85uoFeJnRWeFtLtpR/GHC/TypeLits/KnownNat.hi\n        Something is amiss; requested module  ghc-typelits-knownnat-0.7.2:GHC.TypeLits.KnownNat differs from name found in the interface file array-0.5.4.0:GHC.TypeLits.KnownNat (if these names look the same, try again with -dppr-debug)", _tags = Nothing, _relatedInformation = Nothing}]

Copy link
Collaborator

@pepeiborra pepeiborra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI for GHC 8.10 fails due to the test failure. The following test fails, don't know how to fix it:

  plugins:                                                       FAIL (1.49s)
    test/src/Development/IDE/Test.hs:39:
    Could not find (DsError,(8,14),"Variable not in scope: c") in List [Diagnostic {_range = Range {_start = Position {_line = 0, _character = 0}, _end = Position {_line = 0, _character = 0}}, _severity = Just DsError, _code = Nothing, _source = Just "typecheck", _message = "/tmp/extra-dir-78866602889079/Testing.hs:1:1: error:\n    Bad interface file: /home/vsts/.stack/snapshots/x86_64-linux/0d09385e35771f64a4c4bf9b92b8b30fbc8ce487126f21b5edfae99a26a1d108/8.10.1/lib/x86_64-linux-ghc-8.10.1/ghc-typelits-knownnat-0.7.2-DCI9V85uoFeJnRWeFtLtpR/GHC/TypeLits/KnownNat.hi\n        Something is amiss; requested module  ghc-typelits-knownnat-0.7.2:GHC.TypeLits.KnownNat differs from name found in the interface file array-0.5.4.0:GHC.TypeLits.KnownNat (if these names look the same, try again with -dppr-debug)", _tags = Nothing, _relatedInformation = Nothing}]

I can repro this error locally with a ghc 8.10.1 build via Nix, which removes stack from the equation.
And reproducing what the test does in ghci doesn't show the error, so it's almost certainly not an issue in the related plugin and libraries.

let tc_binds = tcg_binds ts
(asts', arr) <- getCompressedAsts tc_binds rs
let Just src_file = ml_hs_file $ ms_location ms
src <- liftIO $ BS.readFile src_file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is unsuitable for ghcide where files opened in the editor live in a virtual file system, and was the reason that we had to inline this module and change the implementation of mkHieFile. Please revert :)

src-ghc810/Development/IDE/GHC/HieAst.hs Show resolved Hide resolved
@pepeiborra
Copy link
Collaborator

CI for GHC 8.10 fails due to the test failure. The following test fails, don't know how to fix it:

  plugins:                                                       FAIL (1.49s)
    test/src/Development/IDE/Test.hs:39:
    Could not find (DsError,(8,14),"Variable not in scope: c") in List [Diagnostic {_range = Range {_start = Position {_line = 0, _character = 0}, _end = Position {_line = 0, _character = 0}}, _severity = Just DsError, _code = Nothing, _source = Just "typecheck", _message = "/tmp/extra-dir-78866602889079/Testing.hs:1:1: error:\n    Bad interface file: /home/vsts/.stack/snapshots/x86_64-linux/0d09385e35771f64a4c4bf9b92b8b30fbc8ce487126f21b5edfae99a26a1d108/8.10.1/lib/x86_64-linux-ghc-8.10.1/ghc-typelits-knownnat-0.7.2-DCI9V85uoFeJnRWeFtLtpR/GHC/TypeLits/KnownNat.hi\n        Something is amiss; requested module  ghc-typelits-knownnat-0.7.2:GHC.TypeLits.KnownNat differs from name found in the interface file array-0.5.4.0:GHC.TypeLits.KnownNat (if these names look the same, try again with -dppr-debug)", _tags = Nothing, _relatedInformation = Nothing}]

I can repro this error locally with a ghc 8.10.1 build via Nix, which removes stack from the equation.
And reproducing what the test does in ghci doesn't show the error, so it's almost certainly not an issue in the related plugin and libraries.

Following GHC's suggestion to use -dppr-debug, I can confirm that the two names are really the same. Quite confusing:

  /home/pepe/scratch/ghcide/Testing.hs:1:1: error:
  Bad interface file:
  /nix/store/y47mcwxg3xjzm1vncv8vm3km103l1kzn-ghc-typelits-knownnat-0.7.2/lib/ghc-8.10.1/x86_64-linux-ghc-8.10.1/ghc-typelits-knownnat-0.7.2-EOol1HudK6SImK1KLBAdq1/GHC/TypeLits/KnownNat.hi
  Something is amiss; requested module
  ghc-typelits-knownnat-0.7.2-EOol1HudK6SImK1KLBAdq1:GHC.TypeLits.KnownNat differs from name found
  in the interface file ghc-typelits-knownnat-0.7.2-EOol1HudK6SImK1KLBAdq1:GHC.TypeLits.KnownNat (if
  these names look the same, try again with -dppr-debug)

Copy link
Collaborator

@cocreature cocreature left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much! The inlined hie implementation makes me a bit sad but I don’t see a better solution.

It looks like this conflicted with some other PRs merged recently so it needs rebasing. If you run into issues let me know and I’m happy to help!

@chshersh
Copy link
Member Author

chshersh commented May 3, 2020

@cocreature Thanks for the heads up! I've rebased on the latest master and resolved all conflicts.

@cocreature
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -1,8 +1,10 @@
-- Copyright (c) 2019 The DAML Authors. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

{-# LANGUAGE CPP #-}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hlint is failing because we explicitly whitelist modules that are allowed to use CPP. You can just add this module to the list: https://github.com/digital-asset/ghcide/blob/9adb11125ed8c671e802405a272c5c34ec1df0d3/.hlint.yaml#L77

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Should be fixed now.

@cocreature
Copy link
Collaborator

Hm, the test failure still persists. I have to admit that I have no idea what is going wrong here 🤔

@pepeiborra
Copy link
Collaborator

Only the Linux build of 8.10 fails. The windows build succeeds. Platform specific GHC bug?

@cocreature
Copy link
Collaborator

We don’t actually run tests on Windows at all atm. We just check that they compile.

In the interest in moving this forward, how about we open an issue for the failing test and just disable it for 8.10 for now? This still seems like a clear improvement over the status quo so it would be a shame to block it on this.

stack810.yaml Outdated Show resolved Hide resolved
Co-authored-by: Pepe Iborra <pepeiborra@gmail.com>
@chshersh
Copy link
Member Author

@pepeiborra Thanks for the fix! The build seems passing now 👍
@cocreature @mpickering Is there something left to do in this PR?

Copy link
Collaborator

@cocreature cocreature left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@cocreature cocreature merged commit 07cf929 into haskell:master May 11, 2020
pepeiborra added a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* [haskell/ghcide#518] Build ghcide with GHC 8.10.1

Resolves haskell/ghcide#518

* Move CPP logic to the Compat module

* Revert changes to mkHieFile

* Add local fork of HieAst for 8.10.1

The fix for mkHieFile didn't make it into 8.10.1, so the override is still needed

* Ignore hlint in src-ghc810/HieAst.hs

* Whitelist CPP for Development.IDE.GHC.Orphans

* [haskell/ghcide#518] Build ghcide with GHC 8.10.1

Resolves haskell/ghcide#518

* Move CPP logic to the Compat module

* Revert changes to mkHieFile

* Add local fork of HieAst for 8.10.1

The fix for mkHieFile didn't make it into 8.10.1, so the override is still needed

* Ignore hlint in src-ghc810/HieAst.hs

* Whitelist CPP for Development.IDE.GHC.Orphans

* Plugin tests known broken in 8.10.1 (haskell/ghcide#556)

* Bump up ghc-check version

Co-authored-by: Pepe Iborra <pepeiborra@gmail.com>

Co-authored-by: pepe iborra <pepeiborra@gmail.com>
pepeiborra added a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* [haskell/ghcide#518] Build ghcide with GHC 8.10.1

Resolves haskell/ghcide#518

* Move CPP logic to the Compat module

* Revert changes to mkHieFile

* Add local fork of HieAst for 8.10.1

The fix for mkHieFile didn't make it into 8.10.1, so the override is still needed

* Ignore hlint in src-ghc810/HieAst.hs

* Whitelist CPP for Development.IDE.GHC.Orphans

* [haskell/ghcide#518] Build ghcide with GHC 8.10.1

Resolves haskell/ghcide#518

* Move CPP logic to the Compat module

* Revert changes to mkHieFile

* Add local fork of HieAst for 8.10.1

The fix for mkHieFile didn't make it into 8.10.1, so the override is still needed

* Ignore hlint in src-ghc810/HieAst.hs

* Whitelist CPP for Development.IDE.GHC.Orphans

* Plugin tests known broken in 8.10.1 (haskell/ghcide#556)

* Bump up ghc-check version

Co-authored-by: Pepe Iborra <pepeiborra@gmail.com>

Co-authored-by: pepe iborra <pepeiborra@gmail.com>
pepeiborra added a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* [haskell/ghcide#518] Build ghcide with GHC 8.10.1

Resolves haskell/ghcide#518

* Move CPP logic to the Compat module

* Revert changes to mkHieFile

* Add local fork of HieAst for 8.10.1

The fix for mkHieFile didn't make it into 8.10.1, so the override is still needed

* Ignore hlint in src-ghc810/HieAst.hs

* Whitelist CPP for Development.IDE.GHC.Orphans

* [haskell/ghcide#518] Build ghcide with GHC 8.10.1

Resolves haskell/ghcide#518

* Move CPP logic to the Compat module

* Revert changes to mkHieFile

* Add local fork of HieAst for 8.10.1

The fix for mkHieFile didn't make it into 8.10.1, so the override is still needed

* Ignore hlint in src-ghc810/HieAst.hs

* Whitelist CPP for Development.IDE.GHC.Orphans

* Plugin tests known broken in 8.10.1 (haskell/ghcide#556)

* Bump up ghc-check version

Co-authored-by: Pepe Iborra <pepeiborra@gmail.com>

Co-authored-by: pepe iborra <pepeiborra@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build with GHC 8.10
5 participants