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

Unison.Codebase

Synopsis

Documentation

data Codebase m v a Source #

Abstract interface to a user's codebase.

UCM session state

resolveProjectPathIds :: ProjectPathIds -> Transaction ProjectPath Source #

Hydrate the project and branch from IDs.

Terms

$sel:getTerm:Codebase :: Codebase m v a -> TermReferenceId -> Transaction (Maybe (Term v a)) Source #

Get a user-defined term from the codebase.

Note that it is possible to call $sel:putTerm:Codebase, then $sel:getTerm:Codebase, and receive Nothing, per the semantics of $sel:putTerm:Codebase.

unsafeGetTerm :: HasCallStack => Codebase m v a -> Id -> Transaction (Term v a) Source #

Like $sel:getTerm:Codebase, for when the term is known to exist in the codebase.

unsafeGetTermWithType :: HasCallStack => Codebase m v a -> Id -> Transaction (Term v a, Type v a) Source #

Like unsafeGetTerm, but returns the type of the term, too.

unsafeGetTermComponent :: HasCallStack => Codebase m v a -> Hash -> Transaction [(Term v a, Type v a)] Source #

Like $sel:getTermComponentWithTypes:Codebase, for when the term component is known to exist in the codebase.

getTypeOfTerm :: BuiltinAnnotation a => Codebase m Symbol a -> Reference -> Transaction (Maybe (Type Symbol a)) Source #

Get the type of a term.

Note that it is possible to call $sel:putTerm:Codebase, then getTypeOfTerm, and receive Nothing, per the semantics of $sel:putTerm:Codebase.

unsafeGetTypeOfTermById :: HasCallStack => Codebase m v a -> Id -> Transaction (Type v a) Source #

Like getTypeOfTerm, but for when the term is known to exist in the codebase.

isTerm :: BuiltinAnnotation a => Codebase m Symbol a -> Reference -> Transaction Bool Source #

Check whether a reference is a term.

$sel:putTerm:Codebase :: Codebase m v a -> TermReferenceId -> Term v a -> Type v a -> Transaction () Source #

Enqueue the put of a user-defined term (with its type) into the codebase, if it doesn't already exist. The implementation may choose to delay the put until all of the term's (and its type's) references are stored as well.

Referents (sorta-termlike)

getTypeOfReferent :: BuiltinAnnotation a => Codebase m Symbol a -> Referent -> Transaction (Maybe (Type Symbol a)) Source #

Get the type of a referent.

Search

termsOfType :: Var v => Codebase m v a -> Type v a -> Transaction (Set Referent) Source #

Get the set of terms-or-constructors that have the given type.

termsMentioningType :: Var v => Codebase m v a -> Type v a -> Transaction (Set Referent) Source #

Get the set of terms-or-constructors mention the given type anywhere in their signature.

$sel:termReferentsByPrefix:Codebase :: Codebase m v a -> ShortHash -> Transaction (Set Id) Source #

Get the set of user-defined terms-or-constructors whose hash matches the given prefix.

Type declarations

$sel:getTypeDeclaration:Codebase :: Codebase m v a -> TypeReferenceId -> Transaction (Maybe (Decl v a)) Source #

Get a type declaration.

Note that it is possible to call $sel:putTypeDeclaration:Codebase, then $sel:getTypeDeclaration:Codebase, and receive Nothing, per the semantics of $sel:putTypeDeclaration:Codebase.

unsafeGetTypeDeclaration :: HasCallStack => Codebase m v a -> Id -> Transaction (Decl v a) Source #

Like $sel:getTypeDeclaration:Codebase, for when the type declaration is known to exist in the codebase.

$sel:putTypeDeclaration:Codebase :: Codebase m v a -> TypeReferenceId -> Decl v a -> Transaction () Source #

Enqueue the put of a type declaration into the codebase, if it doesn't already exist. The implementation may choose to delay the put until all of the type declaration's references are stored as well.

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

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

Branches

branchExists :: CausalHash -> Transaction Bool Source #

Check whether the given branch exists in the codebase.

expectBranchForHash :: Monad m => Codebase m v a -> CausalHash -> m (Branch m) Source #

Like $sel:getBranchForHash:Codebase, but for when the hash is known to be in the codebase.

$sel:putBranch:Codebase :: Codebase m v a -> Branch m -> m () Source #

Put a branch into the codebase, which includes its children, its patches, and the branch itself, if they don't already exist.

The terms and type declarations that a branch references must already exist in the codebase.

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

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

lca :: MonadIO m => Codebase m v a -> Branch m -> Branch m -> m (Maybe (Branch m)) Source #

Get the lowest common ancestor of two branches, i.e. the most recent branch that is an ancestor of both branches.

getShallowBranchAtPath :: Path -> Branch Transaction -> Transaction (Branch Transaction) Source #

Recursively descend into causals following the given path, Use the root causal if none is provided.

getMaybeShallowBranchAtPath :: Path -> Branch Transaction -> Transaction (Maybe (Branch Transaction)) Source #

Recursively descend into causals following the given path, Use the root causal if none is provided.

getShallowCausalAtPath :: Path -> CausalBranch Transaction -> Transaction (CausalBranch Transaction) Source #

Recursively descend into causals following the given path, Use the root causal if none is provided.

getShallowBranchAtProjectPath :: ProjectPath -> Transaction (Branch Transaction) Source #

Recursively descend into causals following the given path, Use the root causal if none is provided.

getMaybeShallowBranchAtProjectPath :: ProjectPath -> Transaction (Maybe (Branch Transaction)) Source #

Recursively descend into causals following the given path, Use the root causal if none is provided.

preloadProjectBranch :: MonadUnliftIO m => Codebase m v a -> ProjectAndBranch ProjectId ProjectBranchId -> m () Source #

Starts loading the given project branch into cache in a background thread without blocking.

Root branch

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

Patches

patchExists :: PatchHash -> Transaction Bool Source #

Check whether the given patch exists in the codebase.

putPatch :: PatchHash -> Patch -> Transaction () Source #

Put a patch into the codebase.

Note that putBranch may also put patches.

Watches

$sel:getWatch:Codebase :: Codebase m v a -> WatchKind -> TermReferenceId -> Transaction (Maybe (Term v a)) Source #

getWatch k r returns watch result t that was previously put by putWatch k r t.

lookupWatchCache :: Codebase m v a -> Id -> Transaction (Maybe (Term v a)) Source #

Like $sel:getWatch:Codebase, but first looks up the given reference as a regular watch, then as a test watch.

lookupWatchCache codebase ref =
  runMaybeT do
    MaybeT (getWatch codebase RegularWatch ref)
      | MaybeT (getWatch codebase TestWatch ref))

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.

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

clearWatches :: Transaction () #

Delete all watches that were put by putWatch.

Reflog

getDeprecatedRootReflog :: Int -> Transaction [Entry CausalHash Text] #

Gets the specified number of reflog entries in chronological order, most recent first.

getProjectBranchReflog :: Int -> ProjectBranchId -> Transaction [Entry Project ProjectBranch CausalHash] #

Gets the specified number of reflog entries for the specified ProjectBranch in chronological order, most recent first.

getProjectReflog :: Int -> ProjectId -> Transaction [Entry Project ProjectBranch CausalHash] #

Gets the specified number of reflog entries for the given project in chronological order, most recent first.

getGlobalReflog :: Int -> Transaction [Entry Project ProjectBranch CausalHash] #

Gets the specified number of reflog entries in chronological order, most recent first.

Unambiguous hash length

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.

Dependents

dependents :: DependentsSelector -> Reference -> Transaction (Set Reference) Source #

Get the set of terms, type declarations, and builtin types that depend on the given term, type declaration, or builtin type.

Sync

Codebase path

type CodebasePath = FilePath Source #

A directory that contains a codebase.

Direct codebase access

runTransaction :: MonadIO m => Codebase m v a -> Transaction b -> m b Source #

Run a transaction on a codebase.

runTransactionWithRollback :: MonadIO m => Codebase m v a -> ((forall void. b -> Transaction void) -> Transaction b) -> m b Source #

$sel:withConnection:Codebase :: Codebase m v a -> forall x. (Connection -> m x) -> m x Source #

Acquire a new connection to the same underlying database file this codebase object connects to.

$sel:withConnectionIO:Codebase :: Codebase m v a -> forall x. (Connection -> IO x) -> IO x Source #

Acquire a new connection to the same underlying database file this codebase object connects to.

Misc (organize these better)

addDefsToCodebase :: forall m v a. (Var v, Show a) => Codebase m v a -> TypecheckedUnisonFile v a -> Transaction () Source #

installUcmDependencies :: Codebase m Symbol Ann -> Transaction () Source #

Write all of UCM's dependencies (builtins types and an empty namespace) into the codebase

typeLookupForDependencies :: Codebase IO Symbol Ann -> DefnsF Set TermReference TypeReference -> Transaction (TypeLookup Symbol Ann) Source #

Make a TypeLookup that is suitable for looking up information about all of the given type-or-term references, and all of their type dependencies, including builtins.

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.