[GHC] #9220: type roles for unboxed arrays
GHC
ghc-devs at haskell.org
Thu Jun 19 18:03:32 UTC 2014
#9220: type roles for unboxed arrays
-------------------------------------+-------------------------------------
Reporter: rwbarton | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: libraries (other) | Version: 7.8.1
Keywords: | Operating System: Unknown/Multiple
Architecture: Unknown/Multiple | Type of failure: None/Unknown
Difficulty: Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: |
-------------------------------------+-------------------------------------
{{{
rwbarton at morphism:~$ ghci
GHCi, version 7.8.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :i Data.Array.Unboxed.UArray
type role Data.Array.Base.UArray representational phantom
data Data.Array.Base.UArray i e
= Data.Array.Base.UArray !i
!i
{-# UNPACK #-} !Int
GHC.Prim.ByteArray#
-- Defined in ‘Data.Array.Base’
-- [instances trimmed]
Prelude> :i Data.Array.IO.IOUArray
type role Data.Array.IO.Internals.IOUArray representational phantom
newtype Data.Array.IO.Internals.IOUArray i e
= Data.Array.IO.Internals.IOUArray (Data.Array.Base.STUArray
GHC.Prim.RealWorld i e)
-- Defined in ‘Data.Array.IO.Internals’
Prelude> :i Data.Array.ST.STUArray
type role Data.Array.Base.STUArray nominal representational phantom
data Data.Array.Base.STUArray s i e
= Data.Array.Base.STUArray !i
!i
{-# UNPACK #-} !Int
(GHC.Prim.MutableByteArray# s)
-- Defined in ‘Data.Array.Base’
Prelude> :i Data.Array.Storable.StorableArray
type role Data.Array.Storable.Internals.StorableArray representational
phantom
data Data.Array.Storable.Internals.StorableArray i e
= Data.Array.Storable.Internals.StorableArray !i
!i
Int
!(GHC.ForeignPtr.ForeignPtr e)
-- Defined in ‘Data.Array.Storable.Internals’
}}}
These phantom roles for the element types let me create an unboxed array
of one type (like Word8), cast it with `coerce` to another type (like
Word64) and read outside the bounds of the array. I think they should all
be nominal, since a newtype of an existing type could have a totally
unrelated MArray or Storable instance.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9220>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list