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.

makeCachedTransaction :: Ord a => Cache a b -> (a -> Transaction b) -> a -> Transaction b Source #

Given a transaction, return a transaction that first checks a given semispace cache.

The transaction should probably be read-only, as we (of course) don't hit SQLite on a cache hit.

makeMaybeCachedTransaction :: Ord a => Cache a b -> (a -> Transaction (Maybe b)) -> 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, ProjectBranchRow) 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.