Session#
Modules#
Modules a host imports#
A host imports the module that defines each name it uses, mercury_ds’s and the runtime’s alike.
Module |
Names |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
advance, set_clock, set_wall_clock, run_id, tier_id and session_header are also ds.engine’s, over an engine. Mercury resolves each by its arguments’ types, and set_wall_clock by its arity too: ds.engine’s takes no outcome.
(Source: bindings/mercury/src/mercury_ds.m, runtime/mercury/src/ds.dsc.m, runtime/mercury/src/ds.engine.m, runtime/mercury/src/ds.network.m, runtime/mercury/src/ds.value.m)
Sessions#
session#
:- type session.
An engine loaded from one artefact, as a value: the capability of ds_engine_new and ds_engine_load_dsc together.
A call that changes a session takes it and returns the new one, and the value it took stays valid and unchanged. A copy of the value is an independent session, and nothing is freed. A call that changes a session takes no io, but for read_clock and pump_serving, and only pump_serving runs host code.
Note
The halt belongs to the session value that holds it. A value taken before the call that halted the engine is not halted.
(Source: bindings/mercury/src/mercury_ds.session.m)
session_config#
:- type session_config ---> session_config(session_config_clock :: clock_choice, session_config_budget :: fire_budget, session_config_run_id :: maybe(string), session_config_tier_id :: maybe(string), session_config_admission :: admission_policy).
What load configures: the capability of ds_engine_config_t and ds_engine_set_admission.
Field |
Holds |
|---|---|
|
the |
|
|
|
the run id, or |
|
the tier id, or |
|
a map from |
(Source: bindings/mercury/src/mercury_ds.session.m, runtime/mercury/src/ds.engine.m, runtime/mercury/src/ds.dsc.m, Spec: [NLFC.1.2], [NLFC.10.2])
default_config#
:- func default_config = session_config.
The mock clock, no_fire_limit, no run or tier id, and an empty admission map.
(Source: bindings/mercury/src/mercury_ds.session.m)
load#
:- pred load(bitmap::in, session_config::in, maybe_error(session, ds_error)::out, list(report)::out) is det.
Makes a session from an artefact’s bytes, or gives a ds_error saying why not.
encoding, then inval, are checked before the artefact is read. The other refusals are met as the load walks the artefact. A refused load returns no session and no reports.
|
Condition |
|---|---|
|
the run id or tier id is not well-formed UTF-8 |
|
the firing limit is negative |
|
the bytes are empty, or end inside a frame |
|
the first atom is not a |
|
the artefact is of another DS series |
|
the header’s |
|
a later frame or an atom’s body does not decode, a later atom’s field number is 0 or has no registry entry, or an atom is empty |
|
the artefact decodes and breaks a rule of its format, such as |
|
an atom names what the artefact does not hold |
|
an atom’s compression is not |
|
|
|
|
|
a network node’s id is 0, or two nodes share an id |
|
a |
|
a |
On success the reports hold one dsc-load info line for each atom the load steps over by name, DocString, the test and oracle atoms and CompiledCode, with its field number, message and byte offset, in the order the load met them.
(Source: bindings/mercury/src/mercury_ds.session.m, bindings/mercury/src/mercury_ds.from_runtime.m, runtime/mercury/src/ds.dsc.m, runtime/mercury/src/ds.engine.m, Spec: [NLFC.1.2], [RDSC.9.4], [RDSC.11.1])
Running#
step#
:- type step ---> step(step_outcome :: outcome, step_reports :: list(report), step_duties :: list(duty)).
What a call that changes a session did, reported and left the host to do.
step_outcome is an outcome. step_reports is in the order the call emitted them. step_duties is duty values in the order the call produced them, for the host to perform.
(Source: bindings/mercury/src/mercury_ds.session.m)
pumped#
:- type pumped ---> pumped(pumped_outcome :: outcome, pumped_reports :: list(report), pumped_duties :: list(duty), pumped_calls :: list(service_call)).
What a pump did, reported and left the host to do.
pumped_reports is in the order the pump emitted them, pumped_duties in the order its firings produced them, and pumped_calls, each a service_call, in the order its firings issued them.
(Source: bindings/mercury/src/mercury_ds.session.m)
pump#
:- pred pump(pumped::out, session::in, session::out) is det.
Runs the agenda until it is empty or the firing limit is reached: the capability of ds_engine_pump.
The duties and calls are returned and not performed. What the host does with them leaves the session unchanged until it answers a call.
At the limit with activations left, pumped_reports holds a bounds_error naming max_fires_per_pump, and the activations stay queued for the next pump. The limit does not change pumped_outcome.
|
Condition |
|---|---|
|
the session had halted, and the lists are empty; or a firing halted the engine in this pump, whatever else it raised |
|
the pump’s sample, the engine’s first, would give a held cache seed a deadline outside the |
|
a |
|
a rule’s cache write passes a bound |
Of the last two, the first raised is the outcome.
:- pred pump_once(list(duty)::out, session::in, session::out) is det.
pump_once(Duties, !S) :-
pump(Pumped, !S),
Duties = Pumped ^ pumped_duties.
(Source: bindings/mercury/src/mercury_ds.session.m, runtime/mercury/src/ds.engine.m, runtime/mercury/src/ds.events.m, bindings/mercury/src/mercury_ds.from_runtime.m, Spec: [NCBK.2.9], [NLFC.9.5], [LEXP.4.2], [LSTO.4.7.5], [LTIM.2.5.1])
set_fire_budget#
:- pred set_fire_budget(fire_budget::in, outcome::out, session::in, session::out) is det.
Sets how many firings each later pump may perform.
A halted session is refused with engine_halted, ahead of the limit’s check. A negative limit is refused with inval. A refused call leaves the session unchanged.
(Source: bindings/mercury/src/mercury_ds.session.m, Spec: [NCBK.2.9])
Reads#
read(T)#
:- type read(T) ---> ok(T) ; halted(engine_error).
What a read of a session answers: its value, or the error that halted the session’s engine.
Once the engine has halted, every call declared with this type answers halted, as the halt latch states.
:- func live_fact_count(session) = int.
live_fact_count(S) = N :-
( if fact_count(S) = ok(N0) then N = N0 else N = 0 ).
(Source: bindings/mercury/src/mercury_ds.session.m, Spec: [NCBK.2.9], [LERR.1.4.7])
halted#
:- func halted(session) = maybe(engine_error).
The error that halted the engine, or no: the capability of ds_engine_halted.
(Source: bindings/mercury/src/mercury_ds.session.m, Spec: [NCBK.2.9])
memory_usage#
:- func memory_usage(session) = read(engine_mem).
What the engine holds: the capability of ds_engine_mem.
engine_mem has one field for each of ds_engine_mem_t’s members, in its order, each an int, prefixed em_. em_intern_string_bytes and em_total_bytes hold the interned strings’ bytes, and every other byte field is 0. em_wm_fact_count includes the compiler’s synthesised facts, which fact_count leaves out.
(Source: bindings/mercury/src/mercury_ds.session.m, runtime/mercury/src/ds.engine.m, Spec: [NDBG.2.1], [NMET.4.7])
run_id#
:- func run_id(session) = read(maybe(string)).
The run id the session was loaded with, or no: the capability of ds_engine_get_run_id.
(Source: bindings/mercury/src/mercury_ds.session.m, runtime/mercury/src/ds.engine.m)
tier_id#
:- func tier_id(session) = read(maybe(string)).
The tier id the session was loaded with, or no: the capability of ds_engine_get_tier_id.
(Source: bindings/mercury/src/mercury_ds.session.m, runtime/mercury/src/ds.engine.m)
session_header#
:- func session_header(session) = ds.rfcs.stream_meta.
The session header a recording of this session begins with: the capability of ds_engine_get_session_header.
It holds the DS version, the artefact’s dsc_sha256, its capabilities and dialect definition hash, and the run id and tier id, "" for one not given. It answers on a halted session.
(Source: bindings/mercury/src/mercury_ds.session.m, runtime/mercury/src/ds.engine.m, Spec: [NCBK.2.9], [NLFC.1.2], [RBND.1.3])
The runtime’s values#
session_engine#
:- func session_engine(session) = engine.
The session’s engine, the runtime’s own value.
Warning
session_engine refuses nothing after the halt, and a read through its value then has no defined answer.
(Source: bindings/mercury/src/mercury_ds.session.m, Spec: [LERR.1.4.7])
session_program#
:- func session_program(session) = program.
The program the session was loaded from, the runtime’s own value.
ds.dsc.network reads the Rete network from it: the capability of ds_engine_rete_network. It refuses nothing after the halt.
(Source: bindings/mercury/src/mercury_ds.session.m, runtime/mercury/src/ds.dsc.m)