[Git][ghc/ghc][wip/andreask/cast_any] Apply 2 suggestion(s) to 2 file(s)

Andreas Klebinger (@AndreasK) gitlab at gitlab.haskell.org
Tue May 28 12:21:17 UTC 2024



Andreas Klebinger pushed to branch wip/andreask/cast_any at Glasgow Haskell Compiler / GHC


Commits:
c5cc8393 by Sylvain Henry at 2024-05-28T12:20:27+00:00
Apply 2 suggestion(s) to 2 file(s)
- - - - -


2 changed files:

- compiler/GHC/Builtin/Types.hs
- libraries/ghc-internal/src/GHC/Internal/Unsafe/Coerce.hs


Changes:

=====================================
compiler/GHC/Builtin/Types.hs
=====================================
@@ -445,12 +445,15 @@ It has these properties:
   * When instantiated at a lifted type it is inhabited by at least one value,
     namely bottom
 
-  * You can safely coerce any type to Any, and back with unsafeCoerce if the type
-    is lifted. By using unsafeCoerce# we can do the same for *all* types as long as
-    the kinds match up.
-    However for lifted types unsafeCoerce should be used over unsafeCoerce# if
-    possible, as it prevent's us accidentally coercing between different runtime
-    reps.
+  * You can safely coerce any /lifted/ type to Any and back with unsafeCoerce.
+    You can safely coerce any /unlifted/ type to Any and back with unsafeCoerceUnlifted.
+    You can coerce /any/ type to Any and back with unsafeCoerce#, but it's only safe when
+    the kinds of both the type and Any match.
+
+    For lifted/unlifted types unsafeCoerce[Unlifted] should be preferred over unsafeCoerce#
+    as they prevent accidentally coercing between types with kinds that don't match.
+
+    See examples in ghc-prim:GHC.Types
 
   * It does not claim to be a *data* type, and that's important for
     the code generator, because the code gen may *enter* a data value


=====================================
libraries/ghc-internal/src/GHC/Internal/Unsafe/Coerce.hs
=====================================
@@ -337,7 +337,7 @@ unsafeCoerceAddr x = case unsafeEqualityProof @a @b of UnsafeRefl -> x
 -- to trounce upon your data and then laugh in your face. You don't want
 -- this function. Really.
 --
--- This becomes more obvious when looking at it's actual type:
+-- This becomes more obvious when looking at its actual type:
 -- @forall (r1 :: RuntimeRep) (r2 :: RuntimeRep)  (a :: TYPE r1) (b :: TYPE r2). a -> b@
 -- Which often get's rendered as @a -> b@ in haddock for technical reasons.
 unsafeCoerce# :: forall (r1 :: RuntimeRep) (r2 :: RuntimeRep)



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c5cc8393d921814c1ab3043fae9851df91310a5e

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c5cc8393d921814c1ab3043fae9851df91310a5e
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240528/4ff8952f/attachment-0001.html>


More information about the ghc-commits mailing list