module Unison.Runtime.Builtin.Types ( typeReferences, builtinTypeNumbering, builtinTypeBackref, ) where import Data.Map qualified as Map import Unison.Builtin qualified as Ty (builtinTypes) import Unison.Builtin.Decls qualified as Ty import Unison.Prelude hiding (Text, some) import Unison.Reference import Unison.Util.EnumContainers as EC builtinTypeNumbering :: Map Reference Word64 builtinTypeNumbering :: Map Reference Word64 builtinTypeNumbering = [(Reference, Word64)] -> Map Reference Word64 forall k a. Ord k => [(k, a)] -> Map k a Map.fromList [(Reference, Word64)] typeReferences typeReferences :: [(Reference, Word64)] typeReferences :: [(Reference, Word64)] typeReferences = [Reference] -> [Word64] -> [(Reference, Word64)] forall a b. [a] -> [b] -> [(a, b)] zip [Reference] rs [Word64 1 ..] where rs :: [Reference] rs = [Reference r | (Name _, Reference r) <- [(Name, Reference)] Ty.builtinTypes] [Reference] -> [Reference] -> [Reference] forall a. [a] -> [a] -> [a] ++ [Id' Hash -> Reference forall h t. Id' h -> Reference' t h DerivedId Id' Hash i | (Symbol _, Id' Hash i, DataDeclaration Symbol () _) <- [(Symbol, Id' Hash, DataDeclaration Symbol ())] Ty.builtinDataDecls] [Reference] -> [Reference] -> [Reference] forall a. [a] -> [a] -> [a] ++ [Id' Hash -> Reference forall h t. Id' h -> Reference' t h DerivedId Id' Hash i | (Symbol _, Id' Hash i, EffectDeclaration Symbol () _) <- [(Symbol, Id' Hash, EffectDeclaration Symbol ())] Ty.builtinEffectDecls] builtinTypeBackref :: EnumMap Word64 Reference builtinTypeBackref :: EnumMap Word64 Reference builtinTypeBackref = [(Word64, Reference)] -> EnumMap Word64 Reference forall k a. EnumKey k => [(k, a)] -> EnumMap k a mapFromList ([(Word64, Reference)] -> EnumMap Word64 Reference) -> [(Word64, Reference)] -> EnumMap Word64 Reference forall a b. (a -> b) -> a -> b $ (Reference, Word64) -> (Word64, Reference) forall {b} {a}. (b, a) -> (a, b) swap ((Reference, Word64) -> (Word64, Reference)) -> [(Reference, Word64)] -> [(Word64, Reference)] forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> [(Reference, Word64)] typeReferences where swap :: (b, a) -> (a, b) swap (b x, a y) = (a y, b x)