Opened 9 months ago

Closed 9 months ago

#14650 closed bug (fixed)

Panic with no extensions (StgCmmEnv: variable not found)

Reported by: Zemyla Owned by:
Priority: normal Milestone: 8.4.1
Component: Compiler Version: 8.2.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: x86_64 (amd64)
Type of failure: Compile-time crash or panic Test Case: simplCore/should_compile/T14650.hs
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

When I compile the attached Haskell program with -O2, or -O1 with -fspec-constr added, I get a compiler panic:

ghc: panic! (the 'impossible' happened)
  (GHC version 8.2.2 for x86_64-unknown-mingw32):
        StgCmmEnv: variable not found
  $smergeSplit_s3bq
  local binds for:
  $WLL
  $W:%
  $W:&
  cmp_s3ox
  eta_s3oy
  $wmergeLL_s3oz
  $s$wpush_s3pZ
  $wpush_s3q0
  $s$wmergeAll_s3rl
  $wmergeAll_s3rR
  $wsplitDesc_s3sp
  $wsplitAsc_s3sC
  mergeSplit_s3tt
  ss_s3tu
  ds_s3tv
  wild_s3tw
  a1_s3tC
  as'_s3tD
  wild1_s3tE
  b_s3tF
  bs_s3tG
  wild2_s3tH
  ww1_s3tJ
  ww2_s3tK
  ww3_s3tL
  ww4_s3tM
  ww6_s3tO
  ww7_s3tP
  ww8_s3tQ
  ww9_s3tR
  Call stack:
      CallStack (from HasCallStack):
        prettyCurrentCallStack, called at compiler\utils\Outputable.hs:1133:58 in ghc:Outputable
        callStackDoc, called at compiler\utils\Outputable.hs:1137:37 in ghc:Outputable
        pprPanic, called at compiler\codeGen\StgCmmEnv.hs:147:9 in ghc:StgCmmEnv

I ran it with -dcore-lint, and it gives the following messages (full .lint attached):

*** Core Lint errors : in result of Simplifier ***
<no location info>: warning:
    In the expression: jump $smergeSplit_s3bN
                         ww_s34F ww_s34Q ww_s34R ww_s34S ww_s34T
    $smergeSplit_s3bN [Occ=LoopBreaker]
      :: [a_a23n] -> Int# -> Bool -> [a_a23n] -> Stack a_a23n -> [a_a23n]
    [LclId[JoinId(5)],
     Arity=5,
     Str=<S,U><L,U><L,U><L,U><L,U>,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Value=True, ConLike=True,
             WorkFree=True, Expandable=True,
             Guidance=IF_ARGS [80 0 0 0 0] 554 0}] is out of scope
<no location info>: warning:
    In the expression: jump $smergeSplit_s3bN
                         ww_s34F ww_s34Q ww_s34R ww_s34S ww_s34T
    Invalid occurrence of a join variable: $smergeSplit_s3bN
    The binder is either not a join point, or not valid here
<no location info>: warning:
    In the expression: jump $smergeSplit_s3bN
                         ww_s34K ww_s34Q ww_s34R ww_s34S ww_s34T
    $smergeSplit_s3bN [Occ=LoopBreaker]
      :: [a_a23n] -> Int# -> Bool -> [a_a23n] -> Stack a_a23n -> [a_a23n]
    [LclId[JoinId(5)],
     Arity=5,
     Str=<S,U><L,U><L,U><L,U><L,U>,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Value=True, ConLike=True,
             WorkFree=True, Expandable=True,
             Guidance=IF_ARGS [80 0 0 0 0] 554 0}] is out of scope
<no location info>: warning:
    In the expression: jump $smergeSplit_s3bN
                         ww_s34K ww_s34Q ww_s34R ww_s34S ww_s34T
    Invalid occurrence of a join variable: $smergeSplit_s3bN
    The binder is either not a join point, or not valid here

Attachments (1)

MergeSort.zip (9.2 KB) - added by Zemyla 9 months ago.
.Offending program and full core lint for that file

Download all attachments as: .zip

Change History (7)

Changed 9 months ago by Zemyla

Attachment: MergeSort.zip added

.Offending program and full core lint for that file

comment:1 Changed 9 months ago by Zemyla

Oh, I forgot to mention that, when I remove {-# INLINABLE mergeSplit #-}, the crash disappears.

comment:2 Changed 9 months ago by simonpj

I'm on this.

comment:3 Changed 9 months ago by Simon Peyton Jones <simonpj@…>

In 66ff794f/ghc:

Fix join-point decision

This patch moves the "ok_unfolding" test
   from  CoreOpt.joinPointBinding_maybe
   to    OccurAnal.decideJoinPointHood

Previously the occurrence analyser was deciding to make
something a join point, but the simplifier was reversing
that decision, which made the decision about /other/ bindings
invalid.

Fixes Trac #14650.

comment:4 Changed 9 months ago by Simon Peyton Jones <simonpj@…>

In 1c1e46c1/ghc:

preInlineUnconditionally is ok for INLINEABLE

When debugging Trac #14650, I found a place where we had

    let {-# INLINEABLE f #-}
        f = BIG
    in f 7

but 'f' wasn't getting inlined at its unique call site.
There's a good reason for that with INLINE things, which
should only inline when saturated, but not  for INILNEABLE
things.

This patch narrows the case where preInlineUnconditionally
gives up.  It significantly shortens (and improves) the code
for #14650.

comment:5 Changed 9 months ago by simonpj

Status: newmerge
Test Case: simplCore/should_compile/T14650.hs

Thanks for a great report. Now fixed. Worth merging "Fix join-point decision".

(The other patch doesn't fix an outright bug.)

comment:6 Changed 9 months ago by bgamari

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