module Language.PureScript.AST.Declarations.ChainId
  ( ChainId
  , mkChainId
  ) where

import Prelude
import Language.PureScript.AST.SourcePos qualified as Pos
import Control.DeepSeq (NFData)
import Codec.Serialise (Serialise)

-- |
-- For a given instance chain, stores the chain's file name and
-- the starting source pos of the first instance in the chain.
-- This data is used to determine which instances are part of
-- the same instance chain.
newtype ChainId = ChainId (String, Pos.SourcePos)
  deriving (ChainId -> ChainId -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChainId -> ChainId -> Bool
$c/= :: ChainId -> ChainId -> Bool
== :: ChainId -> ChainId -> Bool
$c== :: ChainId -> ChainId -> Bool
Eq, Eq ChainId
ChainId -> ChainId -> Bool
ChainId -> ChainId -> Ordering
ChainId -> ChainId -> ChainId
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ChainId -> ChainId -> ChainId
$cmin :: ChainId -> ChainId -> ChainId
max :: ChainId -> ChainId -> ChainId
$cmax :: ChainId -> ChainId -> ChainId
>= :: ChainId -> ChainId -> Bool
$c>= :: ChainId -> ChainId -> Bool
> :: ChainId -> ChainId -> Bool
$c> :: ChainId -> ChainId -> Bool
<= :: ChainId -> ChainId -> Bool
$c<= :: ChainId -> ChainId -> Bool
< :: ChainId -> ChainId -> Bool
$c< :: ChainId -> ChainId -> Bool
compare :: ChainId -> ChainId -> Ordering
$ccompare :: ChainId -> ChainId -> Ordering
Ord, Int -> ChainId -> ShowS
[ChainId] -> ShowS
ChainId -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChainId] -> ShowS
$cshowList :: [ChainId] -> ShowS
show :: ChainId -> String
$cshow :: ChainId -> String
showsPrec :: Int -> ChainId -> ShowS
$cshowsPrec :: Int -> ChainId -> ShowS
Show, ChainId -> ()
forall a. (a -> ()) -> NFData a
rnf :: ChainId -> ()
$crnf :: ChainId -> ()
NFData, [ChainId] -> Encoding
ChainId -> Encoding
forall s. Decoder s [ChainId]
forall s. Decoder s ChainId
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
decodeList :: forall s. Decoder s [ChainId]
$cdecodeList :: forall s. Decoder s [ChainId]
encodeList :: [ChainId] -> Encoding
$cencodeList :: [ChainId] -> Encoding
decode :: forall s. Decoder s ChainId
$cdecode :: forall s. Decoder s ChainId
encode :: ChainId -> Encoding
$cencode :: ChainId -> Encoding
Serialise)

mkChainId :: String -> Pos.SourcePos -> ChainId
mkChainId :: String -> SourcePos -> ChainId
mkChainId String
fileName SourcePos
startingSourcePos = (String, SourcePos) -> ChainId
ChainId (String
fileName, SourcePos
startingSourcePos)