Opened 3 years ago

Closed 3 years ago

#12718 closed bug (fixed)

Segmentation fault, runtime representation polymorphism

Reported by: Iceland_jack Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.0.1
Keywords: LevityPolymorphism Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHCi crash Test Case:
Blocked By: Blocking:
Related Tickets: #12779 Differential Rev(s):
Wiki Page:

Description

{-# Language RebindableSyntax, NoImplicitPrelude, MagicHash, RankNTypes, PolyKinds, ViewPatterns, TypeInType, FlexibleInstances #-}

import Prelude hiding (Eq (..), Num(..))
import qualified Prelude as P
import GHC.Prim
import GHC.Types  

class Num (a :: TYPE rep) where
  (+) :: a -> a -> a
  fromInteger :: Integer -> a

instance P.Num a => Num a where
  (+) = (P.+)
  fromInteger = P.fromInteger

instance Num Int# where (+) = (+#); fromInteger (fromInteger -> I# n) = n

u :: Bool
u = isTrue# v_ where
  v_ :: forall rep (a :: TYPE rep). Num a => a
  v_ = fromInteger 10

segfaults

$ ./bin/repo/ghc4/inplace/bin/ghc-stage2 --interactive -ignore-dot-ghci /tmp/tMjN.hs
GHCi, version 8.1.20160930: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( /tmp/tMjN.hs, interpreted )
Ok, modules loaded: Main.
*Main> u
True
*Main> Segmentation fault (core dumped)
$ 

Change History (10)

comment:1 Changed 3 years ago by simonpj

Seems to be a GHCi issue. Works ok when compiled.

comment:2 Changed 3 years ago by Simon Peyton Jones <simonpj@…>

In eefe86d/ghc:

Allow levity-polymorpic arrows

This cures Trac #12668 (and cures the Lint errors you get from
Trac #12718).

The idea is explained in Note [Levity polymorphism], in Kind.hs

comment:3 Changed 3 years ago by simonpj

The patch does not cure the problem; but before the patch this program generated lots of spurious Lint errors.

comment:4 Changed 3 years ago by Iceland_jack

  x2 :: T IntRep INt#

should be Int#?

Edit: Oh and parentheses and one additional colon

x1 :: T LiftedPtrRep Int
x1 = MkT LiftedPtrRep Int (\(x::Int) -> 3)

x2 :: T IntRep Int#
x2 = MkT IntRep Int# (\(x::Int#) -> 3)
Last edited 3 years ago by Iceland_jack (previous) (diff)

comment:5 Changed 3 years ago by simonpj

Yes, thanks, fixed.

comment:6 Changed 3 years ago by osa1

This is because of #12779.

comment:7 Changed 3 years ago by osa1

rwbarton pointed out in #12779 that argument of isTrue# should be 0# or 1#. The documentation also says the same thing in different words:

{-# INLINE isTrue# #-}
-- | Alias for 'tagToEnum#'. Returns True if its parameter is 1# and False
--   if it is 0#.
isTrue# :: Int# -> Bool   -- See Note [Optimizing isTrue#]
isTrue# x = tagToEnum# x

So maybe this is expected and we can close this ticket and #12779.

comment:8 in reply to:  7 Changed 3 years ago by Iceland_jack

Replying to osa1:

rwbarton pointed out in #12779 that argument of isTrue# should be 0# or 1#. [...]

Liquid Haskell be like??

isTrue# :: { v:Int# | v == 0# || v == 1# } -> Bool

comment:9 Changed 3 years ago by simonpj

Keywords: LevityPolymorphism added

comment:10 Changed 3 years ago by goldfire

Resolution: fixed
Status: newclosed

I can't reproduce any more. Closing.

Note: See TracTickets for help on using tickets.