package b0
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=e9aa779e66c08fc763019f16d4706f465d16c05d6400b58fbd0313317ef33ddea51952e2b058db28e65f7ddb7012f328c8bf02d8f1da17bb543348541a2587f0
doc/b0.memo/B0_zero/Op/index.html
Module B0_zero.Op
Source
Build operations.
This module provides a type for specifying operations and their result. Operation execution and caching are respectively handled by the Exec
and Reviver
modules.
Operation status
type failure =
| Exec of string option
(*Execution failure with a potential error msg.
*)| Missing_writes of B0_std.Fpath.t list
(*Write specification failure.
*)| Missing_reads of B0_std.Fpath.t list
(*Read synchronisation failure.
*)
The type for operation failures.
type status =
| Aborted
(*Aborted due to prerequisite failure.
*)| Success
(*Executed successfully.
*)| Failed of failure
(*Executed unsuccessfully.
*)| Waiting
(*Waiting for execution.
*)
The type for operation statuses.
Operations
The type for build operation identifiers.
The type for build operation marks. Marks have no special semantics they are just used to label operations for UI purposes.
The type for build operations.
Waiting on files.
The type for operation kinds.
val make :
id ->
mark:mark ->
time_created:B0_std.Mtime.Span.t ->
time_started:B0_std.Mtime.Span.t ->
duration:B0_std.Mtime.Span.t ->
revived:bool ->
status:status ->
reads:B0_std.Fpath.t list ->
writes:B0_std.Fpath.t list ->
writes_manifest_root:B0_std.Fpath.t option ->
hash:B0_hash.t ->
?post_exec:(op -> unit) ->
?k:(op -> unit) ->
kind ->
t
make
constructs an operation. See the corresponding accessors for the semantics of various arguments.
time_created o
is o
's creation time.
time_started o
is o
's execution start time. This is different from B0_std.Mtime.Span.max_span
once the operation has been submitted for execution.
time_ended o
is o
's execution end time. This is different from B0_std.Mtime.Span.max_span
once the operation has been completed and collected.
waited
is o
's waiting time between creation and execution.
duration
is o
's execution duration time.
revived o
is true
iff o
was revived from a cache. Only relevant if hash
is not B0_std.Hash.nil
.
reads o
are the file paths read by the operation.
writes o
are the file paths written by o
.
writes_manifest_root o
if Some root
, the operation is cached using a manifest key. This means the writes
made relative to root
are stored along-side the cache key.
hash o
is the operation's hash. This is B0_std.Hash.nil
before the operation hash has been effectively computed and set via set_hash
. This remains B0_std.Hash.nil
for operations that are not revivable.
supports_reviving o
is true
if operation o
can be revived. This is only valid after the hash of o
been effectively computed and set via set_hash
.
disable_reviving o
disables the ability to revive operation o
. If o
has been revived this is a nop. This only works after the hash been effectively computed and set via set_hash
, for example in post execution call backs.
FIXME. This function is dodgy.
Updating the build operation
exec_k o ()
invokes and discards o
's continuation. Note that this does not protect against the continuation raising.
exec_post_exec o
invokes and discards o
's post execution hook. This hook called is right after the operation execution and, if applicable, before reviver recording. It is always called even if the operation fails or is revived (use status
and revived
to check these conditions). Note that if the hook unexpectedly raises this turns o
in to a failure.
abort o
sets the status of o
to Op.status.Aborted
and discards the operation closures (including kind specific ones).
set_time_started o t
sets o
's execution start time to t
.
set_time_ended o t
sets o
's execution end time to s
.
set_status_from_result o r
sets status of operation o
to Executed
if r
is Ok _
and Failed (Exec e)
if r
is Error e
.
set_reads t fs
sets the file paths read by o
to fs
. Note that this resets the hash
.
set_writes t fs
sets the file paths written by o
to fs
.
set_writes_manifest_root t r
sets the writes manifest root to r
.
Operation sets and map
Analyzing operations
did_not_write o
compares writes
with the current state of the file system and reports those files that do not exist.
cannot_read o
compares reads
with the current state of the file system and reports those files that cannot be read.
unready_reads os
are the file read by os
that are not written by those and not in ready_roots
.
read_write_maps ops
is reads, writes
with reads
mapping file paths to operations that reads them and writes
mapping file paths to operations that write them.
write_map os
is snd (read_write_maps os)
. If one of the operation sets in the map is not a singleton the operations should likely not be run toghether.
find_read_write_cycle os
is Some cs
if there exists a read/write cycle among the operations os
. This means each each element of cs
writes a file read by its successor in the list with the successor of the last element being the first.
type aggregate_error =
| Failures
(*Some operations failed.
*)| Cycle of t list
(*Dependency cycle.
*)| Never_became_ready of B0_std.Fpath.Set.t
(*Some files never became ready.
*)
The type for errors related to a list of operations. This is:
Failures
, if there is one or more operations in the list thatFailed
.Cycle ops
, if there is a set ofWaiting
operations in the list whose individual reads and writes leads to a dependency cycle. See alsofind_read_write_cycle
.Never_became_ready fs
, withfs
files that are in the reads ofWaiting
operations but are written by no operation from the list and were not made ready.
Note that formally more than one of these conditions can be true at the same time. But Never_became_ready
is only reported once the first two kind of errors have been ruled out. The reason is that those files that never became ready may be created by continuations of the failed or cyclic operations and reporting them would not lead the user to focus on the right cause.
val find_aggregate_error :
ready_roots:B0_std.Fpath.Set.t ->
t list ->
(unit, aggregate_error) result
find_aggregate_error ~ready_roots os
finds an aggregate error among the list of operation os
, assuming files ready_roots
were made ready. This is Ok ()
if all operations os
are Success
.
type build_correctness_error =
| Read_before_written of {
file : B0_std.Fpath.t;
writer : t;
readers : t list;
}
| Multiple_writes of {
file : B0_std.Fpath.t;
writers : t list;
}
The type for build correctness errors.
Important. The first kind of error indicates a bug in the memo abstraction, not in user memo usage.
find_build_correctness_errors ops
finds correctness errors in the set of operations ops
. More precisely it checks that for each written file in ops
:
- It is written by a single operation in
ops
- If the previous point is satisfied. That each operation that reads the written file, is started after the the operation that writes the file has finished. Note that this should be guaranteed by the memo abstraction.