Opened 3 years ago

Closed 3 years ago

#5441 closed bug (fixed)

unsafeCoerce'ing function to GHC.Prim.Any causes segfault

Reported by: ulfn Owned by: simonmar
Priority: normal Milestone:
Component: Compiler Version: 7.2.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: x86
Type of failure: Runtime crash Difficulty:
Test Case: simplCore/should_run/T5441 Blocked By:
Blocking: Related Tickets:

Description (last modified by simonpj)

The following module is the smallest one I've been able to find exhibiting the bug. Any simplification (that I've tried) results in the problem going away.

module Any where

import Unsafe.Coerce (unsafeCoerce)
import GHC.Prim (Any)

listmap :: (a -> b) -> [a] -> [b]
listmap f []       = []
listmap f (x : xs) = f x : listmap f xs

data Nat = Z | S Nat
 
{-# NOINLINE inject #-}
inject :: Nat -> Nat -> Nat
inject m i = i

{-# NOINLINE look #-}
look :: Nat -> String -> Char
look Z _ = '0'

showDigit :: Nat -> () -> Nat -> Char
showDigit base prf d = look (inject base d) ""

toDigits :: Nat -> Nat -> [Nat]
toDigits Z Z = [Z]

coe1 :: (Nat -> String) -> Any
coe1 = unsafeCoerce

coe2 :: Any -> (Nat -> String)
coe2 = unsafeCoerce

showInBase :: Nat -> Any
showInBase base
  = coe1 (\n -> listmap
                (showDigit base ())
                (toDigits base n))

showNat :: Nat -> String
showNat = coe2 (showInBase Z)

Now given this main module (it needs to be a different module)

import Any
main = putStrLn (showNat Z)

Compiling with optimisations:

$ ghc -O --make Main.hs
...
$ ./Main
Bus error: 10

Without optimizations it prints 0 as expected.

This has been reproduced on 7.0.3 (Mac OS X) and 7.2.1 (some Linux).

Attachments (2)

Any.hs (771 bytes) - added by ulfn 3 years ago.
Any.hs
Main.hs (42 bytes) - added by ulfn 3 years ago.
Main.hs

Download all attachments as: .zip

Change History (7)

Changed 3 years ago by ulfn

Any.hs

Changed 3 years ago by ulfn

Main.hs

comment:1 Changed 3 years ago by ulfn

  • Type of failure changed from None/Unknown to Runtime crash

Wiki-fu fail. New attempt with proper code block (can I edit the original?)

module Any where

import Unsafe.Coerce (unsafeCoerce)
import GHC.Prim (Any)

listmap :: (a -> b) -> [a] -> [b]
listmap f []       = []
listmap f (x : xs) = f x : listmap f xs

data Nat = Z | S Nat
 
{-# NOINLINE inject #-}
inject :: Nat -> Nat -> Nat
inject m i = i

{-# NOINLINE look #-}
look :: Nat -> String -> Char
look Z _ = '0'

showDigit :: Nat -> () -> Nat -> Char
showDigit base prf d = look (inject base d) ""

toDigits :: Nat -> Nat -> [Nat]
toDigits Z Z = [Z]

coe1 :: (Nat -> String) -> Any
coe1 = unsafeCoerce

coe2 :: Any -> (Nat -> String)
coe2 = unsafeCoerce

showInBase :: Nat -> Any
showInBase base
  = coe1 (\n -> listmap
                (showDigit base ())
                (toDigits base n))

showNat :: Nat -> String
showNat = coe2 (showInBase Z)
-- Main.hs
import Any
main = putStrLn (showNat Z)
$ ghc -O --make Main.hs
$ ./Main
Bus error: 10

comment:2 Changed 3 years ago by simonmar

  • Owner set to simonmar

comment:3 Changed 3 years ago by simonmar

Compiling this with a DEBUG 7.3.today gives a ton of warnings from CoreArity and an ASSERT failure in CoreToStg, so clearly something is wrong:

[1 of 2] Compiling Any              ( Any.hs, Any.o )
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=IF_ARGS [0] 60 0}]
    lvl_shA =
      \ (d_aec :: Any.Nat) ->
        Any.look
          (Any.inject base_aed d_aec) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (Nth: 1
            (<Any.Nat -> GHC.Base.String>
             -> UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any)
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=IF_ARGS [0] 60 0}]
    lvl_shA =
      \ (d_aec :: Any.Nat) ->
        Any.look
          (Any.inject base_aed d_aec) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=IF_ARGS [0] 60 0}]
    lvl_shA =
      \ (d_aec :: Any.Nat) ->
        Any.look
          (Any.inject base_aed d_aec) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=IF_ARGS [0] 60 0}]
    lvl_shA =
      \ (d_aec :: Any.Nat) ->
        Any.look
          (Any.inject base_aed d_aec) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/simplCore/SimplCore.lhs line 574
Simplifier baling out after 4 iterations [30, 1, 1, 1] Size = 110
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=IF_ARGS [0] 60 0}]
    lvl_shA =
      \ (d_aec :: Any.Nat) ->
        Any.look
          (Any.inject base_aed d_aec) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=IF_ARGS [0] 60 0}]
    lvl_shA =
      \ (d_aec :: Any.Nat) ->
        Any.look
          (Any.inject base_aed d_aec) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=IF_ARGS [0] 60 0}]
    lvl_shA =
      \ (d_aec :: Any.Nat) ->
        Any.look
          (Any.inject base_aed d_aec) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=IF_ARGS [0] 60 0}]
    lvl_shA =
      \ (d_aec :: Any.Nat) ->
        Any.look
          (Any.inject base_aed d_aec) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/simplCore/SimplCore.lhs line 574
Simplifier baling out after 4 iterations [1, 1, 1, 1] Size = 110
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=IF_ARGS [0] 60 0}]
    lvl_shA =
      \ (d_aec :: Any.Nat) ->
        Any.look
          (Any.inject base_aed d_aec) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=IF_ARGS [0] 60 0}]
    lvl_shA =
      \ (d_aec :: Any.Nat) ->
        Any.look
          (Any.inject base_aed d_aec) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=IF_ARGS [0] 60 0}]
    lvl_shA =
      \ (d_aec :: Any.Nat) ->
        Any.look
          (Any.inject base_aed d_aec) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=IF_ARGS [0] 60 0}]
    lvl_shA =
      \ (d_aec :: Any.Nat) ->
        Any.look
          (Any.inject base_aed d_aec) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/simplCore/SimplCore.lhs line 574
Simplifier baling out after 4 iterations [1, 1, 1, 1] Size = 110
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    $wlvl_shT :: Any.Nat -> GHC.Prim.Char#
    [LclId,
     Arity=1,
     Str=DmdType S,
     Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=IF_ARGS [0] 70 0}]
    $wlvl_shT =
      \ (w_shO :: Any.Nat) ->
        case Any.look
               (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char)
        of _ { GHC.Types.C# ww_shR ->
        ww_shR
        } } in
  let {
    lvl_shA [InlPrag=INLINE[0]] :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Str=DmdType Sm,
     Unf=Unf{Src=Worker=$wlvl_shT, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=ALWAYS_IF(unsat_ok=True,boring_ok=False)
             Tmpl= \ (w_shO [Occ=Once] :: Any.Nat) ->
                     Any.look
                       (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char)}]
    lvl_shA =
      \ (w_shO :: Any.Nat) ->
        Any.look
          (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA [InlPrag=INLINE[0]] :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Str=DmdType Sm,
     Unf=Unf{Src=InlineStable, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=ALWAYS_IF(unsat_ok=True,boring_ok=False)
             Tmpl= \ (w_shO [Occ=Once] :: Any.Nat) ->
                     Any.look
                       (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char)}]
    lvl_shA =
      \ (w_shO :: Any.Nat) ->
        Any.look
          (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA [InlPrag=INLINE[0]] :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Str=DmdType Sm,
     Unf=Unf{Src=InlineStable, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=ALWAYS_IF(unsat_ok=True,boring_ok=False)
             Tmpl= \ (w_shO [Occ=Once] :: Any.Nat) ->
                     Any.look
                       (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char)}]
    lvl_shA =
      \ (w_shO :: Any.Nat) ->
        Any.look
          (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA [InlPrag=INLINE[0]] :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Str=DmdType Sm,
     Unf=Unf{Src=InlineStable, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=ALWAYS_IF(unsat_ok=True,boring_ok=False)
             Tmpl= \ (w_shO [Occ=Once] :: Any.Nat) ->
                     Any.look
                       (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char)}]
    lvl_shA =
      \ (w_shO :: Any.Nat) ->
        Any.look
          (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/simplCore/SimplCore.lhs line 574
Simplifier baling out after 4 iterations [15, 1, 1, 1] Size = 110
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA [InlPrag=INLINE[0]] :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Str=DmdType Sm,
     Unf=Unf{Src=InlineStable, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=ALWAYS_IF(unsat_ok=True,boring_ok=False)
             Tmpl= \ (w_shO [Occ=Once] :: Any.Nat) ->
                     Any.look
                       (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char)}]
    lvl_shA =
      \ (w_shO :: Any.Nat) ->
        Any.look
          (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA [InlPrag=INLINE[0]] :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Str=DmdType Sm,
     Unf=Unf{Src=InlineStable, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=ALWAYS_IF(unsat_ok=True,boring_ok=False)
             Tmpl= \ (w_shO [Occ=Once] :: Any.Nat) ->
                     Any.look
                       (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char)}]
    lvl_shA =
      \ (w_shO :: Any.Nat) ->
        Any.look
          (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA [InlPrag=INLINE[0]] :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Str=DmdType Sm,
     Unf=Unf{Src=InlineStable, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=ALWAYS_IF(unsat_ok=True,boring_ok=False)
             Tmpl= \ (w_shO [Occ=Once] :: Any.Nat) ->
                     Any.look
                       (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char)}]
    lvl_shA =
      \ (w_shO :: Any.Nat) ->
        Any.look
          (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
\ (base_aed :: Any.Nat) ->
  let {
    lvl_shA [InlPrag=INLINE[0]] :: Any.Nat -> GHC.Types.Char
    [LclId,
     Arity=1,
     Str=DmdType Sm,
     Unf=Unf{Src=InlineStable, TopLvl=False, Arity=1, Value=True,
             ConLike=True, Cheap=True, Expandable=True,
             Guidance=ALWAYS_IF(unsat_ok=True,boring_ok=False)
             Tmpl= \ (w_shO [Occ=Once] :: Any.Nat) ->
                     Any.look
                       (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char)}]
    lvl_shA =
      \ (w_shO :: Any.Nat) ->
        Any.look
          (Any.inject base_aed w_shO) (GHC.Types.[] @ GHC.Types.Char) } in
  (\ (n_aee :: Any.Nat) ->
     Any.listmap
       @ Any.Nat @ GHC.Types.Char lvl_shA (Any.toDigits base_aed n_aee))
  `cast` (UnsafeCo (Any.Nat -> GHC.Base.String) GHC.Prim.Any
          :: (Any.Nat -> GHC.Base.String) ~ GHC.Prim.Any)
WARNING: file compiler/simplCore/SimplCore.lhs line 574
Simplifier baling out after 4 iterations [1, 1, 1, 1] Size = 110
WARNING: file compiler/coreSyn/CoreArity.lhs line 779
1 GHC.Prim.Any
Any.showInBase Any.Z
ghc-stage3: panic! (the 'impossible' happened)
  (GHC version 7.3.20110905 for x86_64-unknown-linux):
        ASSERT failed! file compiler/stgSyn/CoreToStg.lhs line 244
main:Any.showNat1{v rhW} [gid]
Id arity: 1
STG arity: 0

comment:4 Changed 3 years ago by simonpj@…

commit 1466b0ca760a18afbcab9c4128f6a05d220a5968

Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Fri Sep 9 10:04:55 2011 +0100

    Obey the exprArity invariants!  Fixes Trac #5441
    
    We were giving arity 2 to a function whose type was
        Int -> Any
    That contradicts the exprArity invariant
    (see Note [exprArity invariant] in CoreArity), and
    in turn led to function whose actually code-generated arity
    was different that advertised in the interface file.
    Result: seg-fault city.

 compiler/coreSyn/CoreArity.lhs |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

comment:5 Changed 3 years ago by simonpj

  • Description modified (diff)
  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to simplCore/should_run/T5441

Ulf, thank you for identifying a nice small test case. Very helpful. Agda stresses unsafeCoerce like nothing else.

Try now.

Simon

Note: See TracTickets for help on using tickets.