Movatterモバイル変換


[0]ホーム

URL:


{-# LANGUAGE Unsafe #-}{-# LANGUAGE NoImplicitPrelude #-}{-# LANGUAGE MagicHash #-}{-# LANGUAGE ScopedTypeVariables #-}{-# LANGUAGE KindSignatures #-}{-# LANGUAGE DataKinds #-}{-# LANGUAGE PolyKinds #-}------------------------------------------------------------------------------- |-- Module      :  GHC.Prim.PtrEq-- License     :  see libraries/ghc-prim/LICENSE---- Maintainer  :  ghc-devs@haskell.org-- Stability   :  internal-- Portability :  non-portable (GHC Extensions)---- Comparing underlying pointers for equality.---- Use GHC.Exts from the base package instead of importing this-- module directly.-------------------------------------------------------------------------------moduleGHC.Prim.PtrEq(reallyUnsafePtrEquality,unsafePtrEquality#,sameArray#,sameMutableArray#,sameSmallArray#,sameSmallMutableArray#,sameByteArray#,sameMutableByteArray#,sameMutVar#,sameTVar#,sameMVar#,sameIOPort#,samePromptTag#,eqStableName#)whereimportGHC.PrimimportGHC.Types-- Also make implicit dependency known to build system(RuntimeRep(BoxedRep),UnliftedType)default()-- Double and Integer aren't available yet{- ***********************************************************************                                                                       **                        Pointer equality                               **                                                                       *********************************************************************** -}{- Note [Pointer equality operations]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Many primitive types - such as Array#, ByteArray#, MVar#, ... - are boxed:they are represented by pointers to the underlying data. It is thus possibleto directly compare these pointers for equality, as opposed to comparingthe underlying data that the pointers refer to (for instance, comparingtwo arrays element-wise).To do this, GHC provides the primop reallyUnsafePtrEquality#, which isboth levity-polymorphic and heterogeneous. As its name indicates, it is anunsafe operation which can yield unpredictable results, as explained inNote [Pointer comparison operations] in primops.txt.ppFor a more user-friendly interface, this module defines specialisations ofthe reallyUnsafePtrEquality# primop at various primitive types, such asArray#, ByteArray#, MVar#, ...-}-- | Compare the underlying pointers of two values for equality.---- Returns @1@ if the pointers are equal and @0@ otherwise.---- The two values must be of the same type, of kind 'Type'.-- See also 'GHC.Exts.reallyUnsafePtrEquality#', which doesn't have-- such restrictions.reallyUnsafePtrEquality::a->a->Int#reallyUnsafePtrEquality :: forall a. a -> a -> Int#reallyUnsafePtrEquality=a -> a -> Int#forall a b. a -> b -> Int#reallyUnsafePtrEquality#-- See Note [Pointer comparison operations]--   in primops.txt.pp-- | Compare the underlying pointers of two unlifted values for equality.---- This is less dangerous than 'reallyUnsafePtrEquality',-- since the arguments are guaranteed to be evaluated.-- This means there is no risk of accidentally comparing-- a thunk.-- It's however still more dangerous than e.g. 'sameArray#'.--unsafePtrEquality#::forall(a::UnliftedType)(b::UnliftedType).a->b->Int#unsafePtrEquality# :: forall (a :: UnliftedType) (b :: UnliftedType). a -> b -> Int#unsafePtrEquality#=a -> b -> Int#forall a b. a -> b -> Int#reallyUnsafePtrEquality#-- See Note [Pointer comparison operations]--   in primops.txt.pp-- | Compare the underlying pointers of two arrays.sameArray#::forall{l}(a::TYPE(BoxedRepl)).Array#a->Array#a->Int#sameArray# :: forall a. Array# a -> Array# a -> Int#sameArray#=Array# a -> Array# a -> Int#forall (a :: UnliftedType) (b :: UnliftedType). a -> b -> Int#unsafePtrEquality#-- | Compare the underlying pointers of two mutable arrays.sameMutableArray#::forall{l}s(a::TYPE(BoxedRepl)).MutableArray#sa->MutableArray#sa->Int#sameMutableArray# :: forall s a. MutableArray# s a -> MutableArray# s a -> Int#sameMutableArray#=MutableArray# s a -> MutableArray# s a -> Int#forall (a :: UnliftedType) (b :: UnliftedType). a -> b -> Int#unsafePtrEquality#-- | Compare the underlying pointers of two small arrays.sameSmallArray#::forall{l}(a::TYPE(BoxedRepl)).SmallArray#a->SmallArray#a->Int#sameSmallArray# :: forall a. SmallArray# a -> SmallArray# a -> Int#sameSmallArray#=SmallArray# a -> SmallArray# a -> Int#forall (a :: UnliftedType) (b :: UnliftedType). a -> b -> Int#unsafePtrEquality#-- | Compare the underlying pointers of two small mutable arrays.sameSmallMutableArray#::forall{l}s(a::TYPE(BoxedRepl)).SmallMutableArray#sa->SmallMutableArray#sa->Int#sameSmallMutableArray# :: forall s a.SmallMutableArray# s a -> SmallMutableArray# s a -> Int#sameSmallMutableArray#=SmallMutableArray# s a -> SmallMutableArray# s a -> Int#forall (a :: UnliftedType) (b :: UnliftedType). a -> b -> Int#unsafePtrEquality#-- | Compare the pointers of two byte arrays.sameByteArray#::ByteArray#->ByteArray#->Int#sameByteArray# :: ByteArray# -> ByteArray# -> Int#sameByteArray#=ByteArray# -> ByteArray# -> Int#forall (a :: UnliftedType) (b :: UnliftedType). a -> b -> Int#unsafePtrEquality#-- | Compare the underlying pointers of two mutable byte arrays.sameMutableByteArray#::MutableByteArray#s->MutableByteArray#s->Int#sameMutableByteArray# :: forall s. MutableByteArray# s -> MutableByteArray# s -> Int#sameMutableByteArray#=MutableByteArray# s -> MutableByteArray# s -> Int#forall (a :: UnliftedType) (b :: UnliftedType). a -> b -> Int#unsafePtrEquality#-- | Compare the underlying pointers of two 'MutVar#'s.sameMutVar#::forall{l}s(a::TYPE(BoxedRepl)).MutVar#sa->MutVar#sa->Int#sameMutVar# :: forall s a. MutVar# s a -> MutVar# s a -> Int#sameMutVar#=MutVar# s a -> MutVar# s a -> Int#forall (a :: UnliftedType) (b :: UnliftedType). a -> b -> Int#unsafePtrEquality#-- | Compare the underlying pointers of two 'TVar#'s.sameTVar#::forall{l}s(a::TYPE(BoxedRepl)).TVar#sa->TVar#sa->Int#sameTVar# :: forall s a. TVar# s a -> TVar# s a -> Int#sameTVar#=TVar# s a -> TVar# s a -> Int#forall (a :: UnliftedType) (b :: UnliftedType). a -> b -> Int#unsafePtrEquality#-- | Compare the underlying pointers of two 'MVar#'s.sameMVar#::forall{l}s(a::TYPE(BoxedRepl)).MVar#sa->MVar#sa->Int#sameMVar# :: forall s a. MVar# s a -> MVar# s a -> Int#sameMVar#=MVar# s a -> MVar# s a -> Int#forall (a :: UnliftedType) (b :: UnliftedType). a -> b -> Int#unsafePtrEquality#-- | Compare the underlying pointers of two 'IOPort#'s.sameIOPort#::forall{l}s(a::TYPE(BoxedRepl)).IOPort#sa->IOPort#sa->Int#sameIOPort# :: forall s a. IOPort# s a -> IOPort# s a -> Int#sameIOPort#=IOPort# s a -> IOPort# s a -> Int#forall (a :: UnliftedType) (b :: UnliftedType). a -> b -> Int#unsafePtrEquality#-- | Compare the underlying pointers of two 'PromptTag#'s.samePromptTag#::foralla.PromptTag#a->PromptTag#a->Int#samePromptTag# :: forall a. PromptTag# a -> PromptTag# a -> Int#samePromptTag#=PromptTag# a -> PromptTag# a -> Int#forall (a :: UnliftedType) (b :: UnliftedType). a -> b -> Int#unsafePtrEquality#-- Note [Comparing stable names]-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-- A StableName# is actually a pointer to a stable name object (SNO)-- containing an index into the stable name table (SNT). We-- used to compare StableName#s by following the pointers to the-- SNOs and checking whether they held the same SNT indices. However,-- this is not necessary: there is a one-to-one correspondence-- between SNOs and entries in the SNT, so simple pointer equality-- does the trick.-- | Compare two stable names for equality.eqStableName#::forall{k}{l}(a::TYPE(BoxedRepk))(b::TYPE(BoxedRepl)).StableName#a->StableName#b->Int#eqStableName# :: forall a b. StableName# a -> StableName# b -> Int#eqStableName#=StableName# a -> StableName# b -> Int#forall (a :: UnliftedType) (b :: UnliftedType). a -> b -> Int#unsafePtrEquality#

[8]ページ先頭

©2009-2025 Movatter.jp