pub struct Registry { /* private fields */ }Expand description
The kernel’s library registry: the authoritative store of loaded libraries and their resolved exports.
The registry is catalog-backed for identity (the catalog field) and keeps
projection caches over that catalog for fast lookup by symbol, id, and kind.
It owns stable-id allocation, export registration, querying, transactional
loading, and catalog overlays. The kernel defines this contract; libraries
supply the behavior that gets registered. See the README “Library system”
section.
Implementations§
Source§impl Registry
impl Registry
Sourcepub fn dependency_order(
&self,
manifests: &[LibManifest],
) -> Result<Vec<LibManifest>>
pub fn dependency_order( &self, manifests: &[LibManifest], ) -> Result<Vec<LibManifest>>
Topologically orders the given manifests so each library’s dependencies load first.
Already-loaded libraries satisfy dependencies. Errors with
DependencyVersionMismatch,
MissingDependency, or
CyclicDependency when no order
exists.
Sourcepub fn begin_load(
&self,
manifest: LibManifest,
trusted: bool,
) -> LoadTransaction
pub fn begin_load( &self, manifest: LibManifest, trusted: bool, ) -> LoadTransaction
Starts a LoadTransaction for a library on a private registry copy,
reserving its stable id.
Nothing reaches self until the transaction is handed to
commit_load.
§Examples
use std::sync::Arc;
use sim_kernel::library::{
AbiVersion, Export, LibManifest, LibTarget, Registry, Version,
};
use sim_kernel::{Cx, DefaultFactory, NoopEvalPolicy, Symbol};
let mut cx = Cx::new(Arc::new(NoopEvalPolicy), Arc::new(DefaultFactory));
let answer = cx.factory().bool(true).unwrap();
let manifest = LibManifest {
id: Symbol::new("demo"),
version: Version("0.1.0".to_owned()),
abi: AbiVersion { major: 0, minor: 1 },
target: LibTarget::HostRegistered,
requires: Vec::new(),
capabilities: Vec::new(),
exports: vec![Export::Value { symbol: Symbol::new("answer") }],
};
let mut registry = Registry::default();
let mut txn = registry.begin_load(manifest, true);
txn.linker().value(Symbol::new("answer"), answer.clone()).unwrap();
// Staged on the transaction; the live registry is still empty.
assert!(registry.value_by_symbol(&Symbol::new("answer")).is_none());
let id = registry.commit_load(txn).unwrap();
assert!(registry.lib(&Symbol::new("demo")).is_some());
assert_eq!(registry.value_by_symbol(&Symbol::new("answer")), Some(&answer));
let _ = id;Sourcepub fn commit_load(&mut self, txn: LoadTransaction) -> Result<LibId>
pub fn commit_load(&mut self, txn: LoadTransaction) -> Result<LibId>
Commits a LoadTransaction, folding its staged registrations into this
registry and returning the new library id.
Source§impl Registry
impl Registry
Sourcepub fn with_catalog_overlay<F, R>(&mut self, f: F) -> Result<R>
pub fn with_catalog_overlay<F, R>(&mut self, f: F) -> Result<R>
Runs f against the registry under a catalog overlay, committing on
success and rolling both the catalog and the projection caches back to
their captured state on error.
Source§impl Registry
impl Registry
Sourcepub fn catalog_snapshot(&self) -> CatalogSnapshot
pub fn catalog_snapshot(&self) -> CatalogSnapshot
Returns a snapshot of the registry’s identity catalog.
Sourcepub fn boot_receipt(
&self,
lib_id: LibId,
requested_source: LibSourceSpec,
resolved_source: LibSourceSpec,
) -> Option<LibBootReceipt>
pub fn boot_receipt( &self, lib_id: LibId, requested_source: LibSourceSpec, resolved_source: LibSourceSpec, ) -> Option<LibBootReceipt>
Builds the data-only boot receipt for a loaded library id.
Sourcepub fn subset_for_libs(&self, libs: &[Symbol]) -> Self
pub fn subset_for_libs(&self, libs: &[Symbol]) -> Self
Returns a registry restricted to the named libraries and their exports.
Sourcepub fn export_symbols(
&self,
) -> &BTreeMap<ExportKind, BTreeMap<Symbol, RuntimeId>>
pub fn export_symbols( &self, ) -> &BTreeMap<ExportKind, BTreeMap<Symbol, RuntimeId>>
The full export index, keyed by kind then symbol.
Sourcepub fn functions(&self) -> &BTreeMap<Symbol, FunctionId>
pub fn functions(&self) -> &BTreeMap<Symbol, FunctionId>
The function symbol-to-id index.
Sourcepub fn number_domains(&self) -> &BTreeMap<Symbol, NumberDomainId>
pub fn number_domains(&self) -> &BTreeMap<Symbol, NumberDomainId>
The number-domain symbol-to-id index.
Sourcepub fn tests(&self) -> &BTreeMap<Symbol, RegisteredTest>
pub fn tests(&self) -> &BTreeMap<Symbol, RegisteredTest>
All registered tests, keyed by symbol.
Sourcepub fn tests_for_lib(&self, symbol: &Symbol) -> Option<&[Symbol]>
pub fn tests_for_lib(&self, symbol: &Symbol) -> Option<&[Symbol]>
The symbols of tests owned by the given library, if any.
Sourcepub fn class_value(&self, id: ClassId) -> Option<&Value>
pub fn class_value(&self, id: ClassId) -> Option<&Value>
Resolves a class value by stable id.
Sourcepub fn function_value(&self, id: FunctionId) -> Option<&Value>
pub fn function_value(&self, id: FunctionId) -> Option<&Value>
Resolves a function value by stable id.
Sourcepub fn macro_value(&self, id: MacroId) -> Option<&Value>
pub fn macro_value(&self, id: MacroId) -> Option<&Value>
Resolves a macro value by stable id.
Sourcepub fn shape_value(&self, id: ShapeId) -> Option<&Value>
pub fn shape_value(&self, id: ShapeId) -> Option<&Value>
Resolves a shape value by stable id.
Sourcepub fn codec_value(&self, id: CodecId) -> Option<&Value>
pub fn codec_value(&self, id: CodecId) -> Option<&Value>
Resolves a codec value by stable id.
Sourcepub fn number_domain_value(&self, id: NumberDomainId) -> Option<&Value>
pub fn number_domain_value(&self, id: NumberDomainId) -> Option<&Value>
Resolves a number-domain value by stable id.
Sourcepub fn site_value(&self, id: RuntimeId) -> Option<&Value>
pub fn site_value(&self, id: RuntimeId) -> Option<&Value>
Resolves an opaque site value by runtime id.
Sourcepub fn class_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
pub fn class_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
Resolves a class value by symbol.
Sourcepub fn function_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
pub fn function_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
Resolves a function value by symbol.
Sourcepub fn macro_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
pub fn macro_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
Resolves a macro value by symbol.
Sourcepub fn shape_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
pub fn shape_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
Resolves a shape value by symbol.
Sourcepub fn codec_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
pub fn codec_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
Resolves a codec value by symbol.
Sourcepub fn number_domain_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
pub fn number_domain_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
Resolves a number-domain value by symbol.
Sourcepub fn site_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
pub fn site_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
Resolves an opaque site value by symbol.
Sourcepub fn manifest_by_symbol(&self, symbol: &Symbol) -> Option<&LibManifest>
pub fn manifest_by_symbol(&self, symbol: &Symbol) -> Option<&LibManifest>
Returns the manifest of a loaded library by symbol.
Sourcepub fn test_by_symbol(&self, symbol: &Symbol) -> Option<&Arc<dyn Test>>
pub fn test_by_symbol(&self, symbol: &Symbol) -> Option<&Arc<dyn Test>>
Returns the test implementation registered under symbol.
Sourcepub fn registered_test(&self, symbol: &Symbol) -> Option<&RegisteredTest>
pub fn registered_test(&self, symbol: &Symbol) -> Option<&RegisteredTest>
Returns the full RegisteredTest record for symbol.
Sourcepub fn value_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
pub fn value_by_symbol(&self, symbol: &Symbol) -> Option<&Value>
Resolves a plain value export by symbol.
Sourcepub fn export_symbol_for_value(&self, value: &Value) -> Option<Symbol>
pub fn export_symbol_for_value(&self, value: &Value) -> Option<Symbol>
Returns the export symbol a registered value is bound under, searching every export kind, if any.
Source§impl Registry
impl Registry
Sourcepub fn register_class_value(
&mut self,
symbol: Symbol,
value: Value,
) -> Result<ClassId>
pub fn register_class_value( &mut self, symbol: Symbol, value: Value, ) -> Result<ClassId>
Registers a class value directly, reserving a fresh class id; errors on a duplicate class symbol.
§Examples
use std::sync::Arc;
use sim_kernel::library::Registry;
use sim_kernel::{Cx, DefaultFactory, NoopEvalPolicy, Symbol};
let mut cx = Cx::new(Arc::new(NoopEvalPolicy), Arc::new(DefaultFactory));
let class = cx.factory().bool(true).unwrap();
let mut registry = Registry::default();
let id = registry
.register_class_value(Symbol::new("flag"), class.clone())
.unwrap();
assert_eq!(registry.class_by_symbol(&Symbol::new("flag")), Some(&class));
assert_eq!(registry.class_value(id), Some(&class));
// A duplicate class symbol is rejected.
assert!(registry.register_class_value(Symbol::new("flag"), class).is_err());Sourcepub fn register_function_value(
&mut self,
symbol: Symbol,
value: Value,
) -> Result<FunctionId>
pub fn register_function_value( &mut self, symbol: Symbol, value: Value, ) -> Result<FunctionId>
Registers a function value directly, reserving a fresh function id; errors on a duplicate function symbol.
Sourcepub fn register_macro_value(
&mut self,
symbol: Symbol,
value: Value,
) -> Result<MacroId>
pub fn register_macro_value( &mut self, symbol: Symbol, value: Value, ) -> Result<MacroId>
Registers a macro value directly, reserving a fresh macro id; errors on a duplicate macro symbol.
Sourcepub fn register_shape_value(
&mut self,
symbol: Symbol,
value: Value,
) -> Result<ShapeId>
pub fn register_shape_value( &mut self, symbol: Symbol, value: Value, ) -> Result<ShapeId>
Registers a shape value directly, reserving a fresh shape id; errors on a duplicate shape symbol.
Sourcepub fn register_codec_value(
&mut self,
symbol: Symbol,
value: Value,
) -> Result<CodecId>
pub fn register_codec_value( &mut self, symbol: Symbol, value: Value, ) -> Result<CodecId>
Registers a codec value directly, reserving a fresh codec id; errors on a duplicate codec symbol.
Sourcepub fn register_number_domain_value(
&mut self,
symbol: Symbol,
value: Value,
) -> Result<NumberDomainId>
pub fn register_number_domain_value( &mut self, symbol: Symbol, value: Value, ) -> Result<NumberDomainId>
Registers a number-domain value directly, reserving a fresh id; errors on a duplicate number-domain symbol.
Sourcepub fn register_site_value(
&mut self,
symbol: Symbol,
value: Value,
) -> Result<RuntimeId>
pub fn register_site_value( &mut self, symbol: Symbol, value: Value, ) -> Result<RuntimeId>
Registers an opaque site value directly, reserving a fresh site id; errors on a duplicate site symbol.
Sourcepub fn sorted_number_domains(&mut self) -> Vec<(Symbol, Value)>
pub fn sorted_number_domains(&mut self) -> Vec<(Symbol, Value)>
Returns registered number domains ordered by parse priority (descending), then by symbol; the order is computed once and cached.
Sourcepub fn register_test(
&mut self,
symbol: Symbol,
lib: Symbol,
test: Arc<dyn Test>,
subjects: Vec<Symbol>,
) -> Result<()>
pub fn register_test( &mut self, symbol: Symbol, lib: Symbol, test: Arc<dyn Test>, subjects: Vec<Symbol>, ) -> Result<()>
Registers a library-supplied test under symbol; errors on a duplicate
test symbol.
Sourcepub fn register_value(&mut self, symbol: Symbol, value: Value) -> Result<()>
pub fn register_value(&mut self, symbol: Symbol, value: Value) -> Result<()>
Registers a plain value export by symbol; errors on a duplicate value symbol.
Sourcepub fn register_value_for_lib(
&mut self,
lib: &Symbol,
symbol: Symbol,
value: Value,
) -> Result<()>
pub fn register_value_for_lib( &mut self, lib: &Symbol, symbol: Symbol, value: Value, ) -> Result<()>
Registers a plain value and records it as a resolved export of lib.
Sourcepub fn append_export_record(
&mut self,
lib: &Symbol,
record: ExportRecord,
) -> Result<()>
pub fn append_export_record( &mut self, lib: &Symbol, record: ExportRecord, ) -> Result<()>
Appends an export record to an already-loaded library, indexing it as a runtime export when resolved; errors on an unknown lib or duplicate kind+symbol.
Sourcepub fn register_number_binary_op(&mut self, op: NumberBinaryOp)
pub fn register_number_binary_op(&mut self, op: NumberBinaryOp)
Registers a typed number binary operator.
Sourcepub fn register_value_number_binary_op(&mut self, op: ValueNumberBinaryOp)
pub fn register_value_number_binary_op(&mut self, op: ValueNumberBinaryOp)
Registers a value-level number binary operator.
Sourcepub fn register_number_unary_op(&mut self, op: NumberUnaryOp)
pub fn register_number_unary_op(&mut self, op: NumberUnaryOp)
Registers a typed number unary operator.
Sourcepub fn register_value_number_unary_op(&mut self, op: ValueNumberUnaryOp)
pub fn register_value_number_unary_op(&mut self, op: ValueNumberUnaryOp)
Registers a value-level number unary operator.
Sourcepub fn register_number_reduction_op(&mut self, op: NumberReductionOp)
pub fn register_number_reduction_op(&mut self, op: NumberReductionOp)
Registers a typed number reduction operator.
Sourcepub fn register_value_number_reduction_op(&mut self, op: ValueNumberReductionOp)
pub fn register_value_number_reduction_op(&mut self, op: ValueNumberReductionOp)
Registers a value-level number reduction operator.
Sourcepub fn register_promotion_rule(&mut self, rule: PromotionRule)
pub fn register_promotion_rule(&mut self, rule: PromotionRule)
Registers a typed number-domain promotion rule.
Sourcepub fn register_value_promotion_rule(&mut self, rule: ValuePromotionRule)
pub fn register_value_promotion_rule(&mut self, rule: ValuePromotionRule)
Registers a value-level number-domain promotion rule.
Sourcepub fn promotion_rule(
&self,
from_domain: &Symbol,
to_domain: &Symbol,
) -> Option<&PromotionRule>
pub fn promotion_rule( &self, from_domain: &Symbol, to_domain: &Symbol, ) -> Option<&PromotionRule>
Returns the cheapest promotion rule from from_domain to to_domain, if
any.
Sourcepub fn promotion_rules(&self) -> &[PromotionRule]
pub fn promotion_rules(&self) -> &[PromotionRule]
All registered typed promotion rules.
Sourcepub fn value_promotion_rules(&self) -> &[ValuePromotionRule]
pub fn value_promotion_rules(&self) -> &[ValuePromotionRule]
All registered value-level promotion rules.
Sourcepub fn number_binary_ops(&self) -> &[NumberBinaryOp]
pub fn number_binary_ops(&self) -> &[NumberBinaryOp]
All registered typed number binary operators.
Sourcepub fn value_number_binary_ops(&self) -> &[ValueNumberBinaryOp]
pub fn value_number_binary_ops(&self) -> &[ValueNumberBinaryOp]
All registered value-level number binary operators.
Sourcepub fn number_unary_ops(&self) -> &[NumberUnaryOp]
pub fn number_unary_ops(&self) -> &[NumberUnaryOp]
All registered typed number unary operators.
Sourcepub fn value_number_unary_ops(&self) -> &[ValueNumberUnaryOp]
pub fn value_number_unary_ops(&self) -> &[ValueNumberUnaryOp]
All registered value-level number unary operators.
Sourcepub fn number_reduction_ops(&self) -> &[NumberReductionOp]
pub fn number_reduction_ops(&self) -> &[NumberReductionOp]
All registered typed number reduction operators.
Sourcepub fn value_number_reduction_ops(&self) -> &[ValueNumberReductionOp]
pub fn value_number_reduction_ops(&self) -> &[ValueNumberReductionOp]
All registered value-level number reduction operators.
Sourcepub fn number_binary_op(
&self,
operator: &Symbol,
left_domain: &Symbol,
right_domain: &Symbol,
) -> Option<&NumberBinaryOp>
pub fn number_binary_op( &self, operator: &Symbol, left_domain: &Symbol, right_domain: &Symbol, ) -> Option<&NumberBinaryOp>
Returns the cheapest typed binary operator matching the operator and operand domains, if any.
Sourcepub fn fresh_lib_id(&mut self) -> LibId
pub fn fresh_lib_id(&mut self) -> LibId
Reserves a fresh stable library id from the catalog sequence.
Sourcepub fn fresh_class_id(&mut self) -> ClassId
pub fn fresh_class_id(&mut self) -> ClassId
Reserves a fresh stable class id from the catalog sequence.
Sourcepub fn fresh_function_id(&mut self) -> FunctionId
pub fn fresh_function_id(&mut self) -> FunctionId
Reserves a fresh stable function id from the catalog sequence.
Sourcepub fn fresh_macro_id(&mut self) -> MacroId
pub fn fresh_macro_id(&mut self) -> MacroId
Reserves a fresh stable macro id from the catalog sequence.
Sourcepub fn fresh_case_id(&mut self) -> CaseId
pub fn fresh_case_id(&mut self) -> CaseId
Reserves a fresh stable case id from the catalog sequence.
Sourcepub fn fresh_shape_id(&mut self) -> ShapeId
pub fn fresh_shape_id(&mut self) -> ShapeId
Reserves a fresh stable shape id from the catalog sequence.
Sourcepub fn fresh_codec_id(&mut self) -> CodecId
pub fn fresh_codec_id(&mut self) -> CodecId
Reserves a fresh stable codec id from the catalog sequence.
Sourcepub fn fresh_number_domain_id(&mut self) -> NumberDomainId
pub fn fresh_number_domain_id(&mut self) -> NumberDomainId
Reserves a fresh stable number-domain id from the catalog sequence.
Sourcepub fn fresh_site_id(&mut self) -> SiteId
pub fn fresh_site_id(&mut self) -> SiteId
Reserves a fresh stable site id from the catalog sequence.
Source§impl Registry
impl Registry
Sourcepub fn unload(&mut self, lib_id: LibId) -> Result<Vec<LibId>>
pub fn unload(&mut self, lib_id: LibId) -> Result<Vec<LibId>>
Unloads a single library by stable id.
This is a bare unload: if any loaded library depends on lib_id, the
call refuses with Error::LibHasDependents. Passing an absent id is a
no-op and returns an empty list. On success the returned list contains
the unloaded id.