Commit 38c54bd2 authored by ian@well-typed.com's avatar ian@well-typed.com
Browse files

Merge branch 'master' of darcs.haskell.org:/srv/darcs//packages/base

parents edbc826e f9d70457
......@@ -31,10 +31,33 @@
module Unsafe.Coerce (unsafeCoerce) where
#if defined(__GLASGOW_HASKELL__)
import GHC.Prim (unsafeCoerce#)
local_id :: a -> a
local_id x = x -- See Note [Mega-hack for coerce]
{- Note [Meta-hack for coerce]
If we just say
unsafeCoerce x = unsafeCoercs# x
then the simple-optimiser that the desugarer runs will eta-reduce to
unsafeCoerce :: forall (a:*) (b:*). a -> b
unsafeCoercs = unsafeCoerce#
And that, sadly, is ill-typed because unsafeCoercs# has OpenKind type variables
And rightly so, becuase we shouldn't be calling unsafeCoerce# in a higher
order way; it has a compulsory unfolding
unsafeCoerce# a b x = x |> UnsafeCo a b
and we really rely on it being inlined pronto. But the simple-optimiser doesn't.
The identity function local_id delays the eta reduction just long enough
for unsafeCoerce# to get inlined.
Sigh. This is horrible, but then so is unsafeCoerce.
-}
unsafeCoerce :: a -> b
unsafeCoerce x = unsafeCoerce# x
unsafeCoerce x = local_id (unsafeCoerce# x)
-- See Note [Unsafe coerce magic] in basicTypes/MkId
-- NB: Do not eta-reduce this definition, else the type checker
-- give usafeCoerce the same (dangerous) type as unsafeCoerce#
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment