Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module contains sqlite-specific operations on high-level "parser-typechecker" types all in the Transaction monad.
The Codebase record-of-functions wraps this functionality, and runs each transaction to IO, so that the operations'
are unified with non-sqlite operations in the Codebase interface, like appendReflog
.
Synopsis
- createSchema :: Transaction ()
- data BufferEntry a = BufferEntry {}
- prettyBufferEntry :: Show a => Hash -> BufferEntry a -> String
- type TermBufferEntry = BufferEntry (Term Symbol Ann, Type Symbol Ann)
- type DeclBufferEntry = BufferEntry (Decl Symbol Ann)
- getBuffer :: TVar (Map Hash (BufferEntry a)) -> Hash -> IO (BufferEntry a)
- putBuffer :: TVar (Map Hash (BufferEntry a)) -> Hash -> BufferEntry a -> IO ()
- removeBuffer :: TVar (Map Hash (BufferEntry a)) -> Hash -> IO ()
- addBufferDependent :: Hash -> TVar (Map Hash (BufferEntry a)) -> Hash -> IO ()
- tryFlushBuffer :: forall a. Show a => TVar (Map Hash (BufferEntry a)) -> (Hash -> [a] -> Transaction ()) -> (Hash -> Transaction ()) -> Hash -> Transaction ()
- getTerm :: (Reference -> Transaction ConstructorType) -> Id -> Transaction (Maybe (Term Symbol Ann))
- getDeclType :: Reference -> Transaction ConstructorType
- expectDeclTypeById :: Id -> Transaction ConstructorType
- getTypeOfTermImpl :: Id -> Transaction (Maybe (Type Symbol Ann))
- getTermComponentWithTypes :: (Reference -> Transaction ConstructorType) -> Hash -> Transaction (Maybe [(Term Symbol Ann, Type Symbol Ann)])
- getTypeDeclaration :: Id -> Transaction (Maybe (Decl Symbol Ann))
- getDeclComponent :: Hash -> Transaction (Maybe [Decl Symbol Ann])
- expectDeclComponent :: HasCallStack => Hash -> Transaction [Decl Symbol Ann]
- putTermComponent :: TVar (Map Hash TermBufferEntry) -> TVar (Map Hash DeclBufferEntry) -> Hash -> [(Term Symbol Ann, Type Symbol Ann)] -> Transaction ()
- putTerm :: TVar (Map Hash TermBufferEntry) -> TVar (Map Hash DeclBufferEntry) -> Id -> Term Symbol Ann -> Type Symbol Ann -> Transaction ()
- putTerm_ :: TVar (Map Hash TermBufferEntry) -> TVar (Map Hash DeclBufferEntry) -> Id -> Term Symbol Ann -> Type Symbol Ann -> Transaction ()
- tryFlushTermBuffer :: TVar (Map Hash TermBufferEntry) -> Hash -> Transaction ()
- addDeclComponentTypeIndex :: ObjectId -> [[Type Symbol Ann]] -> Transaction ()
- putTypeDeclarationComponent :: TVar (Map Hash TermBufferEntry) -> TVar (Map Hash DeclBufferEntry) -> Hash -> [Decl Symbol Ann] -> Transaction ()
- putTypeDeclaration :: TVar (Map Hash TermBufferEntry) -> TVar (Map Hash DeclBufferEntry) -> Id -> Decl Symbol Ann -> Transaction ()
- putTypeDeclaration_ :: TVar (Map Hash DeclBufferEntry) -> Id -> Decl Symbol Ann -> Transaction ()
- tryFlushDeclBuffer :: TVar (Map Hash TermBufferEntry) -> TVar (Map Hash DeclBufferEntry) -> Hash -> Transaction ()
- getBranchForHash :: BranchCache Transaction -> (Reference -> Transaction ConstructorType) -> CausalHash -> Transaction (Maybe (Branch Transaction))
- putBranch :: Branch Transaction -> Transaction ()
- branchExists :: CausalHash -> Transaction Bool
- getPatch :: PatchHash -> Transaction (Maybe Patch)
- putPatch :: PatchHash -> Patch -> Transaction ()
- patchExists :: PatchHash -> Transaction Bool
- dependentsImpl :: DependentsSelector -> Reference -> Transaction (Set Id)
- dependentsOfComponentImpl :: Hash -> Transaction (Set Id)
- watches :: WatchKind -> Transaction [Id]
- getWatch :: (Reference -> Transaction ConstructorType) -> WatchKind -> Id -> Transaction (Maybe (Term Symbol Ann))
- putWatch :: WatchKind -> Id -> Term Symbol Ann -> Transaction ()
- standardWatchKinds :: [WatchKind]
- termsOfTypeImpl :: (Reference -> Transaction ConstructorType) -> Reference -> Transaction (Set Id)
- termsMentioningTypeImpl :: (Reference -> Transaction ConstructorType) -> Reference -> Transaction (Set Id)
- filterReferencesHavingTypeImpl :: Reference -> Set Id -> Transaction (Set Id)
- filterReferentsHavingTypeImpl :: (Reference -> Transaction ConstructorType) -> Reference -> Set Id -> Transaction (Set Id)
- hashLength :: Transaction Int
- branchHashLength :: Transaction Int
- defnReferencesByPrefix :: ObjectType -> ShortHash -> Transaction (Set Id)
- termReferencesByPrefix :: ShortHash -> Transaction (Set Id)
- typeReferencesByPrefix :: ShortHash -> Transaction (Set Id)
- referentsByPrefix :: (Reference -> Transaction ConstructorType) -> ShortHash -> Transaction (Set Id)
- causalHashesByPrefix :: ShortCausalHash -> Transaction (Set CausalHash)
- termExists :: Hash -> Transaction Bool
- declExists :: Hash -> Transaction Bool
- before :: CausalHash -> CausalHash -> Transaction Bool
- namesAtPath :: BranchHash -> Path -> Transaction Names
- ensureNameLookupForBranchHash :: (Reference -> Transaction ConstructorType) -> Maybe BranchHash -> BranchHash -> Transaction ()
- regenerateNameLookup :: (Reference -> Transaction ConstructorType) -> BranchHash -> Transaction ()
- makeCachedTransaction :: (Ord a, MonadIO m) => Word -> (a -> Transaction b) -> m (a -> Transaction b)
- makeMaybeCachedTransaction :: (Ord a, MonadIO m) => Word -> (a -> Transaction (Maybe b)) -> m (a -> Transaction (Maybe b))
- insertProjectAndBranch :: ProjectName -> ProjectBranchName -> CausalHashId -> Transaction (Project, ProjectBranch)
- emptyCausalHash :: Transaction (CausalHash, CausalHashId)
Documentation
createSchema :: Transaction () Source #
data BufferEntry a Source #
Instances
Show a => Show (BufferEntry a) Source # | |
Defined in Unison.Codebase.SqliteCodebase.Operations showsPrec :: Int -> BufferEntry a -> ShowS # show :: BufferEntry a -> String # showList :: [BufferEntry a] -> ShowS # | |
Eq a => Eq (BufferEntry a) Source # | |
Defined in Unison.Codebase.SqliteCodebase.Operations (==) :: BufferEntry a -> BufferEntry a -> Bool # (/=) :: BufferEntry a -> BufferEntry a -> Bool # |
prettyBufferEntry :: Show a => Hash -> BufferEntry a -> String Source #
type TermBufferEntry = BufferEntry (Term Symbol Ann, Type Symbol Ann) Source #
type DeclBufferEntry = BufferEntry (Decl Symbol Ann) Source #
getBuffer :: TVar (Map Hash (BufferEntry a)) -> Hash -> IO (BufferEntry a) Source #
putBuffer :: TVar (Map Hash (BufferEntry a)) -> Hash -> BufferEntry a -> IO () Source #
removeBuffer :: TVar (Map Hash (BufferEntry a)) -> Hash -> IO () Source #
addBufferDependent :: Hash -> TVar (Map Hash (BufferEntry a)) -> Hash -> IO () Source #
tryFlushBuffer :: forall a. Show a => TVar (Map Hash (BufferEntry a)) -> (Hash -> [a] -> Transaction ()) -> (Hash -> Transaction ()) -> Hash -> Transaction () Source #
:: (Reference -> Transaction ConstructorType) | A |
-> Id | |
-> Transaction (Maybe (Term Symbol Ann)) |
getTypeOfTermImpl :: Id -> Transaction (Maybe (Type Symbol Ann)) Source #
getTermComponentWithTypes Source #
:: (Reference -> Transaction ConstructorType) | A |
-> Hash | |
-> Transaction (Maybe [(Term Symbol Ann, Type Symbol Ann)]) |
getTypeDeclaration :: Id -> Transaction (Maybe (Decl Symbol Ann)) Source #
getDeclComponent :: Hash -> Transaction (Maybe [Decl Symbol Ann]) Source #
expectDeclComponent :: HasCallStack => Hash -> Transaction [Decl Symbol Ann] Source #
Like getDeclComponent
, for when the decl component is known to exist in the codebase.
putTerm :: TVar (Map Hash TermBufferEntry) -> TVar (Map Hash DeclBufferEntry) -> Id -> Term Symbol Ann -> Type Symbol Ann -> Transaction () Source #
putTerm_ :: TVar (Map Hash TermBufferEntry) -> TVar (Map Hash DeclBufferEntry) -> Id -> Term Symbol Ann -> Type Symbol Ann -> Transaction () Source #
tryFlushTermBuffer :: TVar (Map Hash TermBufferEntry) -> Hash -> Transaction () Source #
addDeclComponentTypeIndex :: ObjectId -> [[Type Symbol Ann]] -> Transaction () Source #
putTypeDeclarationComponent :: TVar (Map Hash TermBufferEntry) -> TVar (Map Hash DeclBufferEntry) -> Hash -> [Decl Symbol Ann] -> Transaction () Source #
putTypeDeclaration :: TVar (Map Hash TermBufferEntry) -> TVar (Map Hash DeclBufferEntry) -> Id -> Decl Symbol Ann -> Transaction () Source #
putTypeDeclaration_ :: TVar (Map Hash DeclBufferEntry) -> Id -> Decl Symbol Ann -> Transaction () Source #
tryFlushDeclBuffer :: TVar (Map Hash TermBufferEntry) -> TVar (Map Hash DeclBufferEntry) -> Hash -> Transaction () Source #
:: BranchCache Transaction | A |
-> (Reference -> Transaction ConstructorType) | |
-> CausalHash | |
-> Transaction (Maybe (Branch Transaction)) |
putBranch :: Branch Transaction -> Transaction () Source #
branchExists :: CausalHash -> Transaction Bool Source #
Check whether the given branch exists in the codebase.
putPatch :: PatchHash -> Patch -> Transaction () Source #
Put a patch into the codebase.
Note that putBranch
may also put patches.
patchExists :: PatchHash -> Transaction Bool Source #
Check whether the given patch exists in the codebase.
dependentsImpl :: DependentsSelector -> Reference -> Transaction (Set Id) Source #
dependentsOfComponentImpl :: Hash -> Transaction (Set Id) Source #
watches :: WatchKind -> Transaction [Id] Source #
watches k
returns all of the references r
that were previously put by a putWatch k r t
. t
can be
retrieved by getWatch k r
.
:: (Reference -> Transaction ConstructorType) | A |
-> WatchKind | |
-> Id | |
-> Transaction (Maybe (Term Symbol Ann)) |
putWatch :: WatchKind -> Id -> Term Symbol Ann -> Transaction () Source #
putWatch k r t
puts a watch of kind k
, with hash-of-expression r
and decompiled result t
into the
codebase.
For example, in the watch expression below, k
is Regular
, r
is the hash of x
, and t
is 7
.
> x = 3 + 4 ⧩ 7
:: (Reference -> Transaction ConstructorType) | A |
-> Reference | |
-> Transaction (Set Id) |
termsMentioningTypeImpl Source #
:: (Reference -> Transaction ConstructorType) | A |
-> Reference | |
-> Transaction (Set Id) |
filterReferencesHavingTypeImpl :: Reference -> Set Id -> Transaction (Set Id) Source #
filterReferentsHavingTypeImpl Source #
:: (Reference -> Transaction ConstructorType) | A |
-> Reference | |
-> Set Id | |
-> Transaction (Set Id) |
hashLength :: Transaction Int Source #
The number of base32 characters needed to distinguish any two references in the codebase.
branchHashLength :: Transaction Int Source #
The number of base32 characters needed to distinguish any two branch in the codebase.
defnReferencesByPrefix :: ObjectType -> ShortHash -> Transaction (Set Id) Source #
termReferencesByPrefix :: ShortHash -> Transaction (Set Id) Source #
typeReferencesByPrefix :: ShortHash -> Transaction (Set Id) Source #
Get the set of type declarations whose hash matches the given prefix.
:: (Reference -> Transaction ConstructorType) | A |
-> ShortHash | |
-> Transaction (Set Id) |
causalHashesByPrefix :: ShortCausalHash -> Transaction (Set CausalHash) Source #
Get the set of branches whose hash matches the given prefix.
termExists :: Hash -> Transaction Bool Source #
declExists :: Hash -> Transaction Bool Source #
before :: CausalHash -> CausalHash -> Transaction Bool Source #
namesAtPath :: BranchHash -> Path -> Transaction Names Source #
Construct a ScopedNames
which can produce names which are relative to the provided
Path.
NOTE: this method requires an up-to-date name lookup index
ensureNameLookupForBranchHash Source #
:: (Reference -> Transaction ConstructorType) | |
-> Maybe BranchHash | An optional branch which we may already have an index for. This should be a branch which is relatively similar to the branch we're creating a name lookup for, e.g. a recent ancestor of the new branch. The more similar it is, the faster the less work we'll need to do. |
-> BranchHash | |
-> Transaction () |
Add an index for the provided branch hash if one doesn't already exist.
regenerateNameLookup :: (Reference -> Transaction ConstructorType) -> BranchHash -> Transaction () Source #
Regenerate the name lookup index for the given branch hash from scratch. This shouldn't be necessary in normal operation, but it's useful to fix name lookups if they somehow get corrupt, or during local testing and debugging.
makeCachedTransaction :: (Ord a, MonadIO m) => Word -> (a -> Transaction b) -> m (a -> Transaction b) Source #
Given a transaction, return a transaction that first checks a semispace cache of the given size.
The transaction should probably be read-only, as we (of course) don't hit SQLite on a cache hit.
makeMaybeCachedTransaction :: (Ord a, MonadIO m) => Word -> (a -> Transaction (Maybe b)) -> m (a -> Transaction (Maybe b)) Source #
Like makeCachedTransaction
, but for when the transaction returns a Maybe; only cache the Justs.
insertProjectAndBranch :: ProjectName -> ProjectBranchName -> CausalHashId -> Transaction (Project, ProjectBranch) Source #
Creates a project by name if one doesn't already exist, creates a branch in that project, then returns the project and branch ids. Fails if a branch by that name already exists in the project.
emptyCausalHash :: Transaction (CausalHash, CausalHashId) Source #
Often we need to assign something to an empty causal, this ensures the empty causal exists in the codebase and returns its hash.