Opened 22 months ago

Closed 20 months ago

Last modified 20 months ago

#11414 closed bug (fixed)

Panic with -XStrict: StgCmmEnv: variable not found

Reported by: thomie Owned by:
Priority: highest Milestone: 8.0.1
Component: Compiler Version: 7.11
Keywords: Strict Cc: adamse
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: T11414
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D1791
Wiki Page:

Description (last modified by bgamari)

{-# LANGUAGE Strict #-}
main = print $ let x = undefined in True

Using HEAD or GHC 8.0:

$ ghc-8.0.0.20160109 Test.hs
[1 of 1] Compiling Main             ( Test.hs, Test.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.0.0.20160109 for x86_64-unknown-linux):
	StgCmmEnv: variable not found
  $dIP_aDK
  local binds for:

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Using a devel2 build:

$ ./inplace/bin/ghc-stage2 Test.hs
[1 of 1] Compiling Main             ( Test.hs, Test.o )
WARNING: file compiler/simplCore/OccurAnal.hs, line 66
  Glomming in Main: [aDO :->]
WARNING: file compiler/coreSyn/CoreSubst.hs, line 278
  CoreSubst.lookupIdSubst simpleOptExpr $dIP_aDO
  InScope [aDM :-> a_aDM]
WARNING: file compiler/simplCore/OccurAnal.hs, line 66
  Glomming in Main: [aDO :-> Once]
WARNING: file compiler/simplCore/SimplEnv.hs, line 530 $dIP_aDO
WARNING: file compiler/simplCore/OccurAnal.hs, line 66
  Glomming in Main: [aDO :-> Once]
WARNING: file compiler/simplCore/SimplEnv.hs, line 530 $dIP_aDO
ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 8.1.20160103 for x86_64-unknown-linux):
	ASSERT failed! file compiler/stgSyn/CoreToStg.hs line 1025 $dIP_aDO

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Change History (14)

comment:1 Changed 22 months ago by adamse

Did some very quick testing. At 77ef1a0895b3bfa9236705f4e5ffcd46d6e19ff8 (Dec 14) there is no error:

% ./inplace/bin/ghc-stage2 Test.hs
[1 of 1] Compiling Main             ( Test.hs, Test.o )
Linking Test ...

comment:2 Changed 21 months ago by bgamari

Test Case: T11414

comment:3 Changed 21 months ago by bgamari

Description: modified (diff)
Priority: highhighest

comment:4 Changed 21 months ago by bgamari

It appears that the issue is introduced quite early in compilation as the output from desugaring fails core lint,

*** Core Linted result of Desugar (after optimization):
*** Core Lint errors : in result of Desugar (after optimization) ***
<no location info>: warning:
    In the expression: (\ (@ a_aKO) -> undefined)
                         @ a_aKO @ 'Lifted @ a_aKO $dIP_aKQ
    $dIP_aKQ :: ?callStack::CallStack
    [LclId, Str=DmdType] is out of scope
*** Offending Program ***
main :: IO ()
[LclIdX, Str=DmdType]
main =
  $ @ 'Lifted
    @ Bool
    @ (IO ())
    (print @ Bool $fShowBool)
    (case \ (@ a_aKO) ->
            (\ (@ a_aKO) -> undefined) @ a_aKO @ 'Lifted @ a_aKO $dIP_aKQ
     of _ [Occ=Dead] { __DEFAULT ->
     True
     })

main :: IO ()
[LclIdX, Str=DmdType]
main = runMainIO @ () main

$trModule :: Module
[LclIdX[ReflectionId], Str=DmdType]
$trModule = Module (TrNameS "main"#) (TrNameS "Main"#)

*** End of Offense ***

comment:5 Changed 21 months ago by osa1

I fixed this, submitting a patch in a minute.

comment:6 Changed 21 months ago by osa1

Differential Rev(s): Phab:D1791
Status: newpatch

comment:7 Changed 21 months ago by Ben Gamari <ben@…>

In f3a867e8/ghc:

Add testcase for #11414

Reviewers: austin

Subscribers: thomie

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

GHC Trac Issues: #11414

comment:8 Changed 21 months ago by osa1

So my previous attempt has failed, but, I added some inline comment in the Phabricator ticket to show how it's going wrong, so hopefully that'll help. I'll work on this later today but if someone has a fix please go ahead. (or I can do it if you just write the idea)

comment:9 Changed 21 months ago by osa1

I think @goldfire might have solved it. I updated the patch and am currently waiting for validate.

comment:10 Changed 21 months ago by bgamari

Status: patchnew

Taking out of patch status as we don't yet have a convincing fix.

comment:11 Changed 21 months ago by simonpj

I need to look at this; sorry to have been playing dead.

Last edited 21 months ago by simonpj (previous) (diff)

comment:12 Changed 21 months ago by Simon Peyton Jones <simonpj@…>

In c6485d5e/ghc:

Simplify AbsBinds wrapping

In poking Trac #11414 I found myself sinking into the abe_inst_wrap
swamp.  What is this strange thing?  (It turned out that #11414 was
breaking because of it.)

Thrillingly, I found a way to sweep it away again, putting the deep
instantation into tcMonoBinds instead of mkExport; and it turned out
that the fun_co_fn field of FunBind was already there ready to receive
exactly this wrapper. Hooray.  Result

* Death to abe_inst_wrap
* Death to mbi_orig
* Death to the plumbing in tcPolyInfer that did the
  deep instantiation

I did find that I had to re-engineer the treatment of instance type
signatures (again), but the result looks more modular and robust to
me.

And #11414 is fixed.

comment:13 Changed 21 months ago by simonpj

Status: newmerge

Worth merging this. I'm very happy with it.

comment:14 Changed 20 months ago by bgamari

Resolution: fixed
Status: mergeclosed
Last edited 20 months ago by bgamari (previous) (diff)
Note: See TracTickets for help on using tickets.