| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Unison.Hashing.V2
Contents
Description
This module exports:
- Data types with
ContentAddressableinstances that correspond to v2 of the Unison hash function. - Miscellaneous helper functions related to hashing.
Synopsis
- data Branch = Branch {
- terms :: Map NameSegment (Map Referent MdValues)
- types :: Map NameSegment (Map Reference MdValues)
- patches :: Map NameSegment Hash
- children :: Map NameSegment Hash
- data Causal = Causal {
- branchHash :: Hash
- parents :: Set Hash
- data DataDeclaration v a = DataDeclaration {
- modifier :: Modifier
- annotation :: a
- bound :: [v]
- constructors' :: [(a, v, Type v a)]
- type Decl v a = Either (EffectDeclaration v a) (DataDeclaration v a)
- newtype EffectDeclaration v a = EffectDeclaration {
- toDataDecl :: DataDeclaration v a
- data Kind
- data MatchCase loc a = MatchCase (Pattern loc) (Maybe a) a
- newtype MdValues = MdValues (Set MetadataValue)
- data Modifier
- = Structural
- | Unique Text
- newtype NameSegment = NameSegment Text
- data Patch = Patch {}
- data Pattern loc
- = PatternUnbound loc
- | PatternVar loc
- | PatternBoolean loc !Bool
- | PatternInt loc !Int64
- | PatternNat loc !Word64
- | PatternFloat loc !Double
- | PatternText loc !Text
- | PatternChar loc !Char
- | PatternConstructor loc !Reference !ConstructorId [Pattern loc]
- | PatternAs loc (Pattern loc)
- | PatternEffectPure loc (Pattern loc)
- | PatternEffectBind loc !Reference !ConstructorId [Pattern loc] (Pattern loc)
- | PatternSequenceLiteral loc [Pattern loc]
- | PatternSequenceOp loc (Pattern loc) !SeqOp (Pattern loc)
- data Reference
- pattern ReferenceDerived :: Hash -> Pos -> Reference
- data ReferenceId = ReferenceId Hash Pos
- data Referent
- = ReferentRef Reference
- | ReferentCon Reference ConstructorId
- data SeqOp
- type Term v a = Term2 v a a v a
- data TermEdit
- data TermF typeVar typeAnn patternAnn a
- = TermInt Int64
- | TermNat Word64
- | TermFloat Double
- | TermBoolean Bool
- | TermText Text
- | TermChar Char
- | TermBlank (Blank typeAnn)
- | TermRef Reference
- | TermConstructor Reference ConstructorId
- | TermRequest Reference ConstructorId
- | TermHandle a a
- | TermApp a a
- | TermAnn a (Type typeVar typeAnn)
- | TermList (Seq a)
- | TermIf a a a
- | TermAnd a a
- | TermOr a a
- | TermLam a
- | TermLetRec [a] a
- | TermLet a a
- | TermMatch a [MatchCase patternAnn a]
- | TermTermLink Referent
- | TermTypeLink Reference
- type Type v a = Term TypeF v a
- data TypeEdit
- data TypeF a
- = TypeRef Reference
- | TypeArrow a a
- | TypeAnn a Kind
- | TypeApp a a
- | TypeEffect a a
- | TypeEffects [a]
- | TypeForall a
- | TypeIntroOuter a
- data HashingWarning = IncompleteElementOrderingError (NonEmpty (NonEmpty String))
- crashOnHashingWarning :: HasCallStack => ([HashingWarning], a) -> a
- hashClosedTerm :: Var v => Term v a -> ReferenceId
- hashDecls :: (Eq v, Var v, Show v) => (v -> Name) -> Map v (DataDeclaration v a) -> ResolutionResult a [(v, ReferenceId, DataDeclaration v a)]
- hashTermComponents :: forall v a extra. Var v => Map v (Term v a, Type v a, extra) -> ([HashingWarning], Map v (ReferenceId, Term v a, Type v a, extra))
- hashTermComponentsWithoutTypes :: Var v => Map v (Term v a) -> ([HashingWarning], Map v (ReferenceId, Term v a))
- typeToReference :: (Ord v, Show v) => Type v a -> Reference
- typeToReferenceMentions :: (Ord v, Show v) => Type v a -> Set Reference
- class ContentAddressable a where
- contentHash :: a -> Hash
Documentation
Constructors
| Branch | |
Fields
| |
Instances
| ContentAddressable Causal Source # | |
Defined in Unison.Hashing.V2.Causal Methods contentHash :: Causal -> Hash # | |
data DataDeclaration v a Source #
Constructors
| DataDeclaration | |
Fields
| |
Instances
| Functor (DataDeclaration v) Source # | |
Defined in Unison.Hashing.V2.DataDeclaration Methods fmap :: (a -> b) -> DataDeclaration v a -> DataDeclaration v b # (<$) :: a -> DataDeclaration v b -> DataDeclaration v a # | |
type Decl v a = Either (EffectDeclaration v a) (DataDeclaration v a) Source #
newtype EffectDeclaration v a Source #
Constructors
| EffectDeclaration | |
Fields
| |
Instances
| Functor (EffectDeclaration v) Source # | |
Defined in Unison.Hashing.V2.DataDeclaration Methods fmap :: (a -> b) -> EffectDeclaration v a -> EffectDeclaration v b # (<$) :: a -> EffectDeclaration v b -> EffectDeclaration v a # | |
Instances
| Generic Kind Source # | |
| Read Kind Source # | |
| Show Kind Source # | |
| Eq Kind Source # | |
| Ord Kind Source # | |
| type Rep Kind Source # | |
Defined in Unison.Hashing.V2.Kind type Rep Kind = D1 ('MetaData "Kind" "Unison.Hashing.V2.Kind" "unison-hashing-v2-0.0.0-8lPXbJPlm6sDj9SGQtF5JE" 'False) (C1 ('MetaCons "KindStar" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "KindArrow" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Kind) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Kind))) | |
Instances
Constructors
| Structural | |
| Unique Text |
newtype NameSegment Source #
A name segment.
Constructors
| NameSegment Text |
Instances
| Show NameSegment Source # | |
Defined in Unison.Hashing.V2.NameSegment Methods showsPrec :: Int -> NameSegment -> ShowS # show :: NameSegment -> String # showList :: [NameSegment] -> ShowS # | |
| Eq NameSegment Source # | |
Defined in Unison.Hashing.V2.NameSegment | |
| Ord NameSegment Source # | |
Defined in Unison.Hashing.V2.NameSegment Methods compare :: NameSegment -> NameSegment -> Ordering # (<) :: NameSegment -> NameSegment -> Bool # (<=) :: NameSegment -> NameSegment -> Bool # (>) :: NameSegment -> NameSegment -> Bool # (>=) :: NameSegment -> NameSegment -> Bool # max :: NameSegment -> NameSegment -> NameSegment # min :: NameSegment -> NameSegment -> NameSegment # | |
Constructors
| Patch | |
Instances
| ContentAddressable Patch Source # | |
Defined in Unison.Hashing.V2.Patch Methods contentHash :: Patch -> Hash # | |
Constructors
| PatternUnbound loc | |
| PatternVar loc | |
| PatternBoolean loc !Bool | |
| PatternInt loc !Int64 | |
| PatternNat loc !Word64 | |
| PatternFloat loc !Double | |
| PatternText loc !Text | |
| PatternChar loc !Char | |
| PatternConstructor loc !Reference !ConstructorId [Pattern loc] | |
| PatternAs loc (Pattern loc) | |
| PatternEffectPure loc (Pattern loc) | |
| PatternEffectBind loc !Reference !ConstructorId [Pattern loc] (Pattern loc) | |
| PatternSequenceLiteral loc [Pattern loc] | |
| PatternSequenceOp loc (Pattern loc) !SeqOp (Pattern loc) |
Instances
Either a builtin or a user defined (hashed) top-level declaration.
Used for both terms and types. Doesn't distinguish between them.
Other used defined things like local variables don't get References.
Constructors
| ReferenceBuiltin Text | |
| ReferenceDerivedId ReferenceId |
Instances
| Show Reference Source # | |
| Eq Reference Source # | |
| Ord Reference Source # | |
pattern ReferenceDerived :: Hash -> Pos -> Reference Source #
data ReferenceId Source #
Pos is a position into a cycle of size Size, as cycles are hashed together.
Constructors
| ReferenceId Hash Pos |
Instances
| Show ReferenceId Source # | |
Defined in Unison.Hashing.V2.Reference Methods showsPrec :: Int -> ReferenceId -> ShowS # show :: ReferenceId -> String # showList :: [ReferenceId] -> ShowS # | |
| Eq ReferenceId Source # | |
Defined in Unison.Hashing.V2.Reference | |
| Ord ReferenceId Source # | |
Defined in Unison.Hashing.V2.Reference Methods compare :: ReferenceId -> ReferenceId -> Ordering # (<) :: ReferenceId -> ReferenceId -> Bool # (<=) :: ReferenceId -> ReferenceId -> Bool # (>) :: ReferenceId -> ReferenceId -> Bool # (>=) :: ReferenceId -> ReferenceId -> Bool # max :: ReferenceId -> ReferenceId -> ReferenceId # min :: ReferenceId -> ReferenceId -> ReferenceId # | |
Constructors
| ReferentRef Reference | |
| ReferentCon Reference ConstructorId |
Instances
| Generic SeqOp Source # | |
| Show SeqOp Source # | |
| Eq SeqOp Source # | |
| Ord SeqOp Source # | |
| type Rep SeqOp Source # | |
Defined in Unison.Hashing.V2.Pattern type Rep SeqOp = D1 ('MetaData "SeqOp" "Unison.Hashing.V2.Pattern" "unison-hashing-v2-0.0.0-8lPXbJPlm6sDj9SGQtF5JE" 'False) (C1 ('MetaCons "Cons" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "Snoc" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Concat" 'PrefixI 'False) (U1 :: Type -> Type))) | |
type Term v a = Term2 v a a v a Source #
Like `Term v`, but with an annotation of type a at every level in the tree
Constructors
| TermEditReplace Referent | |
| TermEditDeprecate |
data TermF typeVar typeAnn patternAnn a Source #
Base functor for terms in the Unison language
We need typeVar because the term and type variables may differ.
Constructors
| TermInt Int64 | |
| TermNat Word64 | |
| TermFloat Double | |
| TermBoolean Bool | |
| TermText Text | |
| TermChar Char | |
| TermBlank (Blank typeAnn) | |
| TermRef Reference | |
| TermConstructor Reference ConstructorId | |
| TermRequest Reference ConstructorId | |
| TermHandle a a | |
| TermApp a a | |
| TermAnn a (Type typeVar typeAnn) | |
| TermList (Seq a) | |
| TermIf a a a | |
| TermAnd a a | |
| TermOr a a | |
| TermLam a | |
| TermLetRec [a] a | |
| TermLet a a | |
| TermMatch a [MatchCase patternAnn a] | |
| TermTermLink Referent | |
| TermTypeLink Reference |
Instances
type Type v a = Term TypeF v a Source #
Types are represented as ABTs over the base functor F, with variables in v
Constructors
| TypeEditReplace Reference | |
| TypeEditDeprecate |
Base functor for types in the Unison language
Constructors
| TypeRef Reference | |
| TypeArrow a a | |
| TypeAnn a Kind | |
| TypeApp a a | |
| TypeEffect a a | |
| TypeEffects [a] | |
| TypeForall a | |
| TypeIntroOuter a |
Instances
| Foldable TypeF Source # | |
Defined in Unison.Hashing.V2.Type Methods fold :: Monoid m => TypeF m -> m # foldMap :: Monoid m => (a -> m) -> TypeF a -> m # foldMap' :: Monoid m => (a -> m) -> TypeF a -> m # foldr :: (a -> b -> b) -> b -> TypeF a -> b # foldr' :: (a -> b -> b) -> b -> TypeF a -> b # foldl :: (b -> a -> b) -> b -> TypeF a -> b # foldl' :: (b -> a -> b) -> b -> TypeF a -> b # foldr1 :: (a -> a -> a) -> TypeF a -> a # foldl1 :: (a -> a -> a) -> TypeF a -> a # elem :: Eq a => a -> TypeF a -> Bool # maximum :: Ord a => TypeF a -> a # minimum :: Ord a => TypeF a -> a # | |
| Traversable TypeF Source # | |
| Functor TypeF Source # | |
data HashingWarning Source #
Constructors
| IncompleteElementOrderingError (NonEmpty (NonEmpty String)) | two or more component elements can not be completely ordered with respect to one another https://github.com/unisonweb/unison/issues/2787 |
Instances
| Exception HashingWarning Source # | |
Defined in Unison.Hashing.V2.ABT Methods toException :: HashingWarning -> SomeException # | |
| Show HashingWarning Source # | |
Defined in Unison.Hashing.V2.ABT Methods showsPrec :: Int -> HashingWarning -> ShowS # show :: HashingWarning -> String # showList :: [HashingWarning] -> ShowS # | |
| Eq HashingWarning Source # | |
Defined in Unison.Hashing.V2.ABT Methods (==) :: HashingWarning -> HashingWarning -> Bool # (/=) :: HashingWarning -> HashingWarning -> Bool # | |
| Ord HashingWarning Source # | |
Defined in Unison.Hashing.V2.ABT Methods compare :: HashingWarning -> HashingWarning -> Ordering # (<) :: HashingWarning -> HashingWarning -> Bool # (<=) :: HashingWarning -> HashingWarning -> Bool # (>) :: HashingWarning -> HashingWarning -> Bool # (>=) :: HashingWarning -> HashingWarning -> Bool # max :: HashingWarning -> HashingWarning -> HashingWarning # min :: HashingWarning -> HashingWarning -> HashingWarning # | |
crashOnHashingWarning :: HasCallStack => ([HashingWarning], a) -> a Source #
Crash if hashing produced any warnings.
In the future we will hopefully prevent this error entirely.
hashClosedTerm :: Var v => Term v a -> ReferenceId Source #
hashDecls :: (Eq v, Var v, Show v) => (v -> Name) -> Map v (DataDeclaration v a) -> ResolutionResult a [(v, ReferenceId, DataDeclaration v a)] Source #
compute the hashes of these user defined types and update any free vars corresponding to these decls with the resulting hashes
data List a = Nil | Cons a (List a) becomes something like (List, #xyz, [forall a. #xyz a, forall a. a -> (#xyz a) -> (#xyz a)])
NOTE: technical limitation, this implementation gives diff results if ctors have the same FQN as one of the types. TODO: assert this and bomb if not satisfied, or else do local mangling and unmangling to ensure this doesn't affect the hash.
hashTermComponents :: forall v a extra. Var v => Map v (Term v a, Type v a, extra) -> ([HashingWarning], Map v (ReferenceId, Term v a, Type v a, extra)) Source #
hashTermComponentsWithoutTypes :: Var v => Map v (Term v a) -> ([HashingWarning], Map v (ReferenceId, Term v a)) Source #
Re-exports
class ContentAddressable a where #
A type class that is inhabited by types that can compute a hash of their content.
The base instances of this class should only live in dedicated "hashing packages" such as unison-hashing-v2, whose
types and implementations should never change.
Trivial wrapper instances can be written around these, but note these pipelines from
MyType ==> SomeHashingType ==> Hash must take care not to change the MyType ==> SomeHashingType conversion, once
written.
For example, we might have a representation of some namespace in memory
data Namespace = Namespace Terms Types OtherStuff CachesAndWhatnot
with a somewhat equivalent "hashing" type in some "hashing package", with a ContentAddressable instance
data HashingNamespace = Namespace Terms Types
We can of course make our own convenience instance
instance ContentAddressable Namespace where contentHash = contentHash . namespaceToHashingNamespace
But we must make sure that the implementation of namespaceToHashingNamespace never changes the fields in the
corresponding HashingNamespace, even as features are added to or removed from Namespace.
Methods
contentHash :: a -> Hash #
Instances
| ContentAddressable Branch Source # | |
Defined in Unison.Hashing.V2.Branch Methods contentHash :: Branch -> Hash # | |
| ContentAddressable Causal Source # | |
Defined in Unison.Hashing.V2.Causal Methods contentHash :: Causal -> Hash # | |
| ContentAddressable Patch Source # | |
Defined in Unison.Hashing.V2.Patch Methods contentHash :: Patch -> Hash # | |