Ticket #6067 (closed bug: fixed)

Opened 14 months ago

Last modified 7 months ago

regression: cgrun051(ghci) failing in HEAD

Reported by: simonmar Owned by:
Priority: highest Milestone: 7.6.1
Component: Compiler Version: 7.5
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

=====> cgrun051(ghci) 46 of 79 [0, 0, 0]
cd . && '/64playpen/simonmar/nightly/HEAD-cam-04-unx/x86_64-unknown-linux/inplace/bin/ghc-stage2' -fforce-recomp -dcore-lint -dcmm-lint -dno-debug-output -no-user-package-conf -rtsopts  -fno-ghci-history cgrun051.hs --interactive -v0 -ignore-dot-ghci +RTS -I0.1 -RTS   <cgrun051.genscript 1>cgrun051.interp.stdout 2>cgrun051.interp.stderr
Actual stderr output differs from expected:
--- ./cgrun051.stderr   2012-04-30 18:02:44.638862376 +0100
+++ ./cgrun051.run.stderr       2012-05-01 11:19:15.808880452 +0100
@@ -1 +1 @@
-cgrun051: OK
+cgrun051: Impossible case alternative
*** unexpected failure for cgrun051(ghci)

The code is very simple. For some reason the simplifier is replacing the error "OK" with runtimeError "Impossible case alternative", but only in GHCi.

Change History

  Changed 14 months ago by simonpj

I can see what is happening. We have

   case error "OK" of { x::T1 -> blah }

where T1 is a data type with no constructors.

  • With some level of optimisation GHC sees that error returns bottom, and simplifies to error "OK".
  • But in GHCi, GHC doesn't see the bottom, but instead sees that the case is scrutinising a data type with no constructors, so it replaces the whole case with error "Impossible case alternative".

The latter transformation is really wrong, even with our liberal exception semantics. Really it should only be done if the scrutinee is guaranteed not to raise an exception.

This links to a converstaion I had with Max. The idea is:

  • In Core, allow an empty list of alternatives in case.
  • If the scrutinee provably is bottom, discard all the alternatives (since they are unreachable)

Things to bear in mind:

  • This avoid the need to add "unsafe" coercions.
  • Case expressions would need to carry their type (as they do at present)
  • The code generator should treat (case e of []) just like e.

  Changed 14 months ago by simonpj@…

commit ac230c5ef652e27f61d954281ae6a3195e1f9970

Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Wed May 2 15:44:14 2012 +0100

    Allow cases with empty alterantives
    
    This patch allows, for the first time, case expressions with an empty
    list of alternatives. Max suggested the idea, and Trac #6067 showed
    that it is really quite important.
    
    So I've implemented the idea, fixing #6067. Main changes
    
     * See Note [Empty case alternatives] in CoreSyn
    
     * Various foldr1's become foldrs
    
     * IfaceCase does not record the type of the alternatives.
       I added IfaceECase for empty-alternative cases.
    
     * Core Lint does not complain about empty cases
    
     * MkCore.castBottomExpr constructs an empty-alternative case
       expression   (case e of ty {})
    
     * CoreToStg converts '(case e of {})' to just 'e'

 compiler/coreSyn/CoreArity.lhs     |   10 +++-
 compiler/coreSyn/CoreFVs.lhs       |    2 +-
 compiler/coreSyn/CoreLint.lhs      |    8 ---
 compiler/coreSyn/CoreSyn.lhs       |   53 ++++++++++++++++++++-
 compiler/coreSyn/CoreUnfold.lhs    |    4 +-
 compiler/coreSyn/MkCore.lhs        |   12 ++++-
 compiler/iface/BinIface.hs         |    7 +++
 compiler/iface/IfaceSyn.lhs        |   14 +++++-
 compiler/iface/MkIface.lhs         |    4 +-
 compiler/iface/TcIface.lhs         |    6 ++
 compiler/simplCore/OccurAnal.lhs   |    2 +-
 compiler/simplCore/SimplCore.lhs   |   10 ++--
 compiler/simplCore/SimplUtils.lhs  |   56 +++++++++++-----------
 compiler/simplCore/Simplify.lhs    |   93 ++++++++++++++++++------------------
 compiler/specialise/SpecConstr.lhs |    4 +-
 compiler/specialise/Specialise.lhs |    8 ++--
 compiler/stgSyn/CoreToStg.lhs      |   12 +++++
 compiler/stranal/DmdAnal.lhs       |    2 +-
 18 files changed, 201 insertions(+), 106 deletions(-)

follow-up: ↓ 4   Changed 14 months ago by simonpj

  • status changed from new to closed
  • resolution set to fixed

in reply to: ↑ 3   Changed 7 months ago by pumpkin

Replying to simonpj:

Does this fix #2431?

Note: See TracTickets for help on using tickets.