Opened 2 years ago

Closed 2 years ago

#13591 closed bug (fixed)

"*** Exception: expectJust showModule" in ghci with hs-boot

Reported by: lspitzner Owned by:
Priority: high Milestone: 8.2.1
Component: GHCi Version: 8.2.1-rc1
Keywords: ghci hs-boot Cc: ezyang
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #9450 Differential Rev(s):
Wiki Page:

Description

ghci runs into an exception if there is an error in Foo.hs when there exists a Foo.hs-boot (which compiles fine).

  • First.hs-boot
    module First where
    one :: Int
    
  • Second.hs
    module Second where
    import {-# SOURCE #-} First
    two :: Int
    two = one + 1
    
  • First.hs
    module First where
    import Second
    one :: Int
    one = _
    
> ghci
Prelude> :l First
[1 of 3] Compiling First[boot]      ( First.hs-boot, interpreted )
[2 of 3] Compiling Second           ( Second.hs, interpreted )
[3 of 3] Compiling First            ( First.hs, interpreted )

First.hs:6:7: error:
    • Found hole: _ :: Int
    • In the expression: _
      In an equation for ‘one’: one = _
    • Relevant bindings include one :: Int (bound at First.hs:6:1)
*** Exception: expectJust showModule
CallStack (from HasCallStack):
  error, called at compiler/utils/Maybes.hs:48:27 in ghc:Maybes

This happens on ghc-8.0.1, 8.0.2 and 8.2.1-rc1. The above output is from 8.0.2, but the error seems to be essentially the same on 8.2.1-rc1. It did not happen on 7.10.3.

While ghci continues to work, the exception appears to clear the loaded-modules list, which in turn breaks tooling (ghcid here, which hangs as a consequence). The expected behaviour would be that other modules (which contain no errors) remain loaded.

Change History (10)

comment:1 Changed 2 years ago by Ben Gamari <ben@…>

In f6eaf01/ghc:

testsuite: Add test for #13591

Reviewers: austin

Subscribers: rwbarton, thomie

GHC Trac Issues: #13591

Differential Revision: https://phabricator.haskell.org/D3470

comment:2 Changed 2 years ago by bgamari

Milestone: 8.2.1
Priority: normalhigh

comment:3 Changed 2 years ago by lspitzner

#9887 seems related, as it seems to be the main "consumer" of the function that causes this error. Handling the Nothing-case by returning True could mean that #9887 remains open for hs-boot files, but then I don't understand what exactly the test for linkable is supposed to accomplish in the first place.

When trying to understand the involved code, I noticed that this seems to be a near-perfect example of boolean blindness. Where isObjectLinkable returns a Bool that might reflect pretty closely what the function's name suggests, the value is then "reinterpreted" without any explanation and exposed as isModuleInterpreted. Further, showModule passes the Bool to showModMsg where the argument then is called "recomp" (another reinterpretation):

showModMsg dflags target recomp mod_summary
  = ...
      case target of
        HscInterpreted | recomp -> ...
        -- what we have here, really is:
        -- HscInterpreted | (isModuleInterpreted mod_summary) -> ..
        -- so we have two interpreted-flags? what?
    ...

At this point I have no idea anymore of what the supposed semantic of this Bool is anymore.

All that said, doing

isModuleInterpreted :: GhcMonad m => ModSummary -> m Bool
isModuleInterpreted mod_summary = withSession $ \hsc_env ->
  case lookupUFM (hsc_HPT hsc_env) (ms_mod_name mod_summary) of
        Nothing       -> panic "missing linkable"
        Just mod_info -> return $ case hm_linkable mod_info of
          Nothing       -> True
          Just linkable -> not (isObjectLinkable linkable)

seems to be a quick fix for this. But it does not display something like

Failed, modules loaded: First(First.o-boot), First, Second.

in the case that only First.hs-boot was compiled before (which i guess would be the desired behaviour in this case, right?)

Last edited 2 years ago by lspitzner (previous) (diff)

comment:4 Changed 2 years ago by RyanGlScott

The program in #9450 also experiences this error.

comment:5 Changed 2 years ago by RyanGlScott

Status: newpatch

lspitzner posted a fix for this issue at https://github.com/ghc/ghc/pull/37.

comment:6 Changed 2 years ago by simonpj

Cc: ezyang added

Edward, you know about hs-boot stuff. Might you look?

comment:7 Changed 2 years ago by bgamari

Note that we have a patch for this which resolves the issue as reported. However, I suspect that this bit of code could do with some refactoring.

comment:8 Changed 2 years ago by Ben Gamari <ben@…>

In 1edee7a/ghc:

Fix crash in isModuleInterpreted for HsBoot (fixes #13591)

Rename isModuleInterpreted to moduleIsBootOrNotObjectLinkable
because a) there already is a moduleIsInterpreted function in
the same module b) I have no idea if the (new) semantic of
the bool returned matches some understanding of
"is interpreted".

comment:9 Changed 2 years ago by bgamari

Status: patchmerge

comment:10 Changed 2 years ago by bgamari

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.