Version of bracket with an INLINE pragma to work around https://gitlab.haskell.org/ghc/ghc/-/issues/22824.
Moduleeffectful-core-2.7.1.2GHC2021
Effectful.Internal.Utils
- 1 type
- 8 values
- Packageeffectful-core-2.7.1.2
- Exports10
- LanguageGHC2021
- LicenceBSD-3-Clause
- SourceUtils.hs
Utils for ThreadId
1 declarationGet an id of a thread that doesn't prevent its garbage collection.
Utils for Any
3 declarationsThe type constructor Any :: forall k. k is a type to which you can unsafely coerce any type, and back.
For unsafeCoerce this means for all lifted types t that
unsafeCoerce (unsafeCoerce x :: Any) :: t is equivalent to x and safe.
The same is true for *all* types when using
unsafeCoerce# :: forall (r1 :: RuntimeRep) (r2 :: RuntimeRep)
(a :: TYPE r1) (b :: TYPE r2).
a -> b
but only if you instantiate r1 and r2 to the same runtime representation.
For example using (unsafeCoerce# :: forall (a :: TYPE IntRep) (b :: TYPE IntRep). a -> b) x
is fine, but (unsafeCoerce# :: forall (a :: TYPE IntRep) (b :: TYPE FloatRep). a -> b)
will likely cause seg-faults or worse.
For this resason, users should always prefer unsafeCoerce over unsafeCoerce# when possible.
Here are some more examples:
bad_a1 :: Any (TYPE 'IntRep)
bad_a1 = unsafeCoerce# True
bad_a2 :: Any (TYPE ('BoxedRep 'UnliftedRep))
bad_a2 = unsafeCoerce# True
Here bad_a1 is bad because we started with True :: (Bool :: Type), represented by a boxed heap pointer,
and coerced it to a1 :: Any (TYPE 'IntRep), whose representation is a non-pointer integer.
That's why we had to use bad_a2unsafeCoerce#; it is really unsafe because it can change representations.
Similarly is bad because although both True and bad_a2 are represented by a heap pointer,
True is lifted but bad_a2@ is not; bugs here may be rather subtle.
If you must use unsafeCoerce# to cast to Any, type annotations are recommended
to make sure that Any has the correct kind. As casting between different runtimereps is
unsound. For example to cast a ByteArray# to Any you might use:
unsafeCoerce# b :: (Any :: TYPE ('BoxedRep 'Unlifted))
Unique
2 declarationsA unique with no possibility for CAS contention.
Credits for this go to Edward Kmett.
CallStack
1 declarationRemove exactly one layer of freezing, i.e. the one added by send and
friends via withFrozenCallStack. Freezes applied by client code need to
stay intact, so this must not recurse.
Array capacity
1 declarationGrow capacity of an array.
Utils for MutablePrimArray
1 declarationfillPrimArray Fill a slice of a mutable primitive array with a value.