Opened 9 years ago

Closed 9 years ago

#3150 closed bug (duplicate)

Overlapping data instances can segfault

Reported by: guest Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 6.10.2
Keywords: Cc: ekmett@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

When exploring data families for some fast unboxed tuple representation, we came across the following scenario.

class Foo a where
    data Bar a :: *

instance Foo a where
    data Bar a = PBar a

instance Foo () where
    data Bar () = PUnit
GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( Foo.hs, interpreted )
Ok, modules loaded: Main.
*Main> case PUnit of PBar x -> x
Segmentation fault

It appears the compiler is allowing the refinement of a into () because they overlap, when it shouldn't.

This is less academic than this example, because it affects doing similar operations to automatically unbox tuples of primitives when possible.

Change History (3)

comment:1 Changed 9 years ago by guest

I forgot to mention that was run with

ghci Foo.hs -XTypeFamilies -XFlexibleInstances

-- it didn't even require OverlappingInstances

comment:2 Changed 9 years ago by elliottt

Version: 6.10.16.10.2

This data family definition led to the ability to define a generic cast:

{-# LANGUAGE TypeFamilies #-}

data family T a b t
data instance T a b t  = L a
data instance T a b () = R b

cast :: a -> b
cast x = let L i = R x in i

get :: IO Char
get  = cast ()

This bug was observed in ghc version 6.10.1, 6.10.1.20090326 and 6.10.2.

% ghci test.hs
GHCi, version 6.10.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( test.hs, interpreted )
Ok, modules loaded: Main.
*Main> get
'\4312564'
*Main> get
<interactive>: internal error: stg_ap_v_ret
    (GHC version 6.10.2 for x86_64_unknown_linux)
    Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
zsh: abort      ghci test.hs

comment:3 Changed 9 years ago by chak

Resolution: duplicate
Status: newclosed

Duplicate of #2677. It's a bug in the overlap check. Sorry, didn't get around to this yet.

Note: See TracTickets for help on using tickets.