unison-parser-typechecker-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unison.Codebase.SqliteCodebase.Operations

Description

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

Documentation

tryFlushBuffer :: forall a. Show a => TVar (Map Hash (BufferEntry a)) -> (Hash -> [a] -> Transaction ()) -> (Hash -> Transaction ()) -> Hash -> Transaction () Source #

getTerm Source #

Arguments

:: (Reference -> Transaction ConstructorType)

A getDeclType-like lookup, possibly backed by a cache.

-> Id 
-> Transaction (Maybe (Term Symbol Ann)) 

getTermComponentWithTypes Source #

Arguments

:: (Reference -> Transaction ConstructorType)

A getDeclType-like lookup, possibly backed by a cache.

-> Hash 
-> Transaction (Maybe [(Term Symbol Ann, Type Symbol Ann)]) 

expectDeclComponent :: HasCallStack => Hash -> Transaction [Decl Symbol Ann] Source #

Like getDeclComponent, for when the decl component is known to exist in the codebase.

putTermComponent Source #

Arguments

:: TVar (Map Hash TermBufferEntry) 
-> TVar (Map Hash DeclBufferEntry) 
-> Hash

The hash of the term component.

-> [(Term Symbol Ann, Type Symbol Ann)] 
-> Transaction () 

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.

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.

getWatch Source #

Arguments

:: (Reference -> Transaction ConstructorType)

A getDeclType-like lookup, possibly backed by a cache.

-> 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

termsOfTypeImpl Source #

Arguments

:: (Reference -> Transaction ConstructorType)

A getDeclType-like lookup, possibly backed by a cache.

-> Reference 
-> Transaction (Set Id) 

termsMentioningTypeImpl Source #

Arguments

:: (Reference -> Transaction ConstructorType)

A getDeclType-like lookup, possibly backed by a cache.

-> Reference 
-> Transaction (Set Id) 

filterReferentsHavingTypeImpl Source #

Arguments

:: (Reference -> Transaction ConstructorType)

A getDeclType-like lookup, possibly backed by a cache.

-> 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.

typeReferencesByPrefix :: ShortHash -> Transaction (Set Id) Source #

Get the set of type declarations whose hash matches the given prefix.

referentsByPrefix Source #

Arguments

:: (Reference -> Transaction ConstructorType)

A getDeclType-like lookup, possibly backed by a cache.

-> ShortHash 
-> Transaction (Set Id) 

causalHashesByPrefix :: ShortCausalHash -> Transaction (Set CausalHash) Source #

Get the set of branches whose hash matches the given prefix.

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 #

Arguments

:: (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.