Fix PrelRules.caseRules to account for out-of-range tags
authorSimon Peyton Jones <simonpj@microsoft.com>
Wed, 25 Jul 2018 15:41:16 +0000 (16:41 +0100)
committerBen Gamari <ben@smart-cactus.org>
Tue, 31 Jul 2018 19:53:19 +0000 (15:53 -0400)
commit851f3341953587d9fd2e471994b37ad81f132b1a
tree8db8b8c821eb282b0bb2bf0f5e747196c149bd02
parent09abd1c420532c4274ddaeb5dfa54d7a9123d172
Fix PrelRules.caseRules to account for out-of-range tags

As Trac #15436 points out, it is possible to get
   case dataToTag# (x :: T) of
      DEFAULT -> blah1
      -1#     -> blah2
      0       -> blah3

The (-1#) alterantive is unreachable, because dataToTag# returns
tags in the range [0..n-1] where n is the number of data constructors
in type T.

This actually made GHC crash; now we simply discard the unreachable
alterantive.  See Note [Unreachable caseRules alternatives]
in PrelRules

(cherry picked from commit 9897f6783a58265d5eaef5fb06f04320c7737e87)
compiler/prelude/PrelRules.hs
compiler/prelude/primops.txt.pp
compiler/simplCore/SimplUtils.hs
testsuite/tests/simplCore/should_run/T15436.hs [new file with mode: 0644]
testsuite/tests/simplCore/should_run/T15436.stdout [new file with mode: 0644]
testsuite/tests/simplCore/should_run/all.T