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 1.5 appears to not handle hs-boot files correctly #2365

Closed
sheaf opened this issue Nov 18, 2021 · 6 comments · Fixed by #2377
Closed

HLS 1.5 appears to not handle hs-boot files correctly #2365

sheaf opened this issue Nov 18, 2021 · 6 comments · Fixed by #2377
Labels
component: ghcide type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@sheaf
Copy link
Contributor

sheaf commented Nov 18, 2021

With HLS 1.5 (using GHC 9.0.1), using the VS Code extension on Windows 10, I'm getting errors when running HLS on the GHC codebase. These errors seem to be caused by a problem loading an hi-boot interface file.

Running HLS on GHC commit f8c1c549bbb02cb0a943a9ae49dee922c96d85c4, I'm getting the following errors:

Show/hide interface file errors
GHC.Types.ForeignCall:

• No instance for (Eq (GenUnit UnitId))
    arising from the third field of ‘StaticTarget’ (type ‘Maybe Unit’)
  Possible fix:
    use a standalone 'deriving instance' declaration,
      so you can specify the instance context yourself
• When deriving the instance for (Eq CCallTarget)

• No instance for (Data (GenUnit UnitId))
    arising from the third field of ‘StaticTarget’ (type ‘Maybe Unit’)
  Possible fix:
    use a standalone 'deriving instance' declaration,
      so you can specify the instance context yourself
• When deriving the instance for (Data CCallTarget)

[...]

GHC.Types.Name:

• Can't find interface-file declaration for variable isInteractiveModule
    Probable cause: bug in .hi-boot file, or inconsistent .hi file
    Use -ddump-if-trace to get an idea of which file caused the error
• In the second argument of ‘(||)’, namely
    ‘isInteractiveModule mod’
  In the expression: from == mod || isInteractiveModule mod
  In an equation for ‘nameIsLocalOrFrom’:
      nameIsLocalOrFrom from name
        | Just mod <- nameModule_maybe name
        = from == mod || isInteractiveModule mod
        | otherwise = True

[...]

GHC.Unit.Info:

• Can't find interface-file declaration for type constructor or class UnitKey
    Probable cause: bug in .hi-boot file, or inconsistent .hi file
    Use -ddump-if-trace to get an idea of which file caused the error
• In the first argument of ‘GenUnitInfo’, namely ‘UnitKey’
  In the type ‘GenUnitInfo UnitKey’
  In the type declaration for ‘UnitKeyInfo’

These all seem to do with failing to load the hi-boot file for GHC.Unit.Types.

I have cleared the ghcide cache as well as the _hie_bios folder, and the error persists. Switching back to HLS 1.4 immediately fixes the problem.

@jneira jneira added the type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. label Nov 18, 2021
@jneira
Copy link
Member

jneira commented Nov 18, 2021

Many thanks for reporting the bug quickly, @mpickering just has reported it in irc.
He mentioned that maybe it could be related with the presence of hs-boot files, does it fit your observations?

@sheaf
Copy link
Contributor Author

sheaf commented Nov 18, 2021

Yes, in the case I reported it seems related to the GHC.Unit.Types.hs-boot file.

@jneira
Copy link
Member

jneira commented Nov 18, 2021

Ok, there are at least two tests in ghcide about hs-boot files

, testSessionWait "cyclic module dependency with hs-boot" $ do
let contentA = T.unlines
[ "module ModuleA where"
, "import {-# SOURCE #-} ModuleB"
]
let contentB = T.unlines
[ "{-# OPTIONS -Wmissing-signatures#-}"
, "module ModuleB where"
, "import ModuleA"
-- introduce an artificial diagnostic
, "foo = ()"
]
let contentBboot = T.unlines
[ "module ModuleB where"
]
_ <- createDoc "ModuleA.hs" "haskell" contentA
_ <- createDoc "ModuleB.hs" "haskell" contentB
_ <- createDoc "ModuleB.hs-boot" "haskell" contentBboot
expectDiagnostics [("ModuleB.hs", [(DsWarning, (3,0), "Top-level binding")])]
, testSessionWait "correct reference used with hs-boot" $ do
let contentB = T.unlines
[ "module ModuleB where"
, "import {-# SOURCE #-} ModuleA()"
]
let contentA = T.unlines
[ "module ModuleA where"
, "import ModuleB()"
, "x = 5"
]
let contentAboot = T.unlines
[ "module ModuleA where"
]
let contentC = T.unlines
[ "{-# OPTIONS -Wmissing-signatures #-}"
, "module ModuleC where"
, "import ModuleA"
-- this reference will fail if it gets incorrectly
-- resolved to the hs-boot file
, "y = x"
]
_ <- createDoc "ModuleB.hs" "haskell" contentB
_ <- createDoc "ModuleA.hs" "haskell" contentA
_ <- createDoc "ModuleA.hs-boot" "haskell" contentAboot
_ <- createDoc "ModuleC.hs" "haskell" contentC
expectDiagnostics [("ModuleC.hs", [(DsWarning, (3,0), "Top-level binding")])]

But they did not catch the bug, maybe cause they dont reproduce the bug context

Will try to reproduce with ghcup-hs, it is a relatively small project and contains at least one hs-boot file

@wz1000
Copy link
Collaborator

wz1000 commented Nov 18, 2021

This issue was introduced by ab46fe8 , which changed the logic to compute the GHC session with dependencies for a file.

The GetDependencies rule used to add a dependency edge between a module and its boot module. Now that GetModIface doesn't use that rule anymore, this edge no longer exists, resulting the above error.

@pepeiborra
Copy link
Collaborator

Thanks for the diagnosis @wz1000, I think you are 100% correct. Bummer!

Is anyone able to contribute a test case and a fix? If not, I'll take a look this weekend or next week.

@jneira
Copy link
Member

jneira commented Nov 19, 2021

The ci workflow of the release commit for ghc-9.0.1 executed tests succesfully:

    cyclic module dependency with hs-boot:                                                                OK (1.08s)
    correct reference used with hs-boot:                                                                  OK (1.22s)

Tests dont check the absence of error diagnostics explicitly, so maybe that is the cause they did not catch the bug

@pepeiborra pepeiborra mentioned this issue Nov 20, 2021
@jneira jneira linked a pull request Nov 22, 2021 that will close this issue
@mergify mergify bot closed this as completed in #2377 Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ghcide type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants