Skip to main content

Registry

Struct Registry 

Source
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

Source

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.

Source

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;
Source

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

Source

pub fn with_catalog_overlay<F, R>(&mut self, f: F) -> Result<R>
where F: FnOnce(&mut Self) -> 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

Source

pub fn catalog_snapshot(&self) -> CatalogSnapshot

Returns a snapshot of the registry’s identity catalog.

Source

pub fn libs(&self) -> &[LoadedLib]

All loaded libraries, in load order.

Source

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.

Source

pub fn subset_for_libs(&self, libs: &[Symbol]) -> Self

Returns a registry restricted to the named libraries and their exports.

Source

pub fn lib(&self, symbol: &Symbol) -> Option<&LoadedLib>

Looks up a loaded library by symbol.

Source

pub fn export_symbols( &self, ) -> &BTreeMap<ExportKind, BTreeMap<Symbol, RuntimeId>>

The full export index, keyed by kind then symbol.

Source

pub fn classes(&self) -> &BTreeMap<Symbol, ClassId>

The class symbol-to-id index.

Source

pub fn functions(&self) -> &BTreeMap<Symbol, FunctionId>

The function symbol-to-id index.

Source

pub fn macros(&self) -> &BTreeMap<Symbol, MacroId>

The macro symbol-to-id index.

Source

pub fn shapes(&self) -> &BTreeMap<Symbol, ShapeId>

The shape symbol-to-id index.

Source

pub fn codecs(&self) -> &BTreeMap<Symbol, CodecId>

The codec symbol-to-id index.

Source

pub fn number_domains(&self) -> &BTreeMap<Symbol, NumberDomainId>

The number-domain symbol-to-id index.

Source

pub fn sites(&self) -> &BTreeMap<Symbol, SiteId>

The site symbol-to-id index.

Source

pub fn tests(&self) -> &BTreeMap<Symbol, RegisteredTest>

All registered tests, keyed by symbol.

Source

pub fn tests_for_lib(&self, symbol: &Symbol) -> Option<&[Symbol]>

The symbols of tests owned by the given library, if any.

Source

pub fn class_value(&self, id: ClassId) -> Option<&Value>

Resolves a class value by stable id.

Source

pub fn function_value(&self, id: FunctionId) -> Option<&Value>

Resolves a function value by stable id.

Source

pub fn macro_value(&self, id: MacroId) -> Option<&Value>

Resolves a macro value by stable id.

Source

pub fn shape_value(&self, id: ShapeId) -> Option<&Value>

Resolves a shape value by stable id.

Source

pub fn codec_value(&self, id: CodecId) -> Option<&Value>

Resolves a codec value by stable id.

Source

pub fn number_domain_value(&self, id: NumberDomainId) -> Option<&Value>

Resolves a number-domain value by stable id.

Source

pub fn site_value(&self, id: RuntimeId) -> Option<&Value>

Resolves an opaque site value by runtime id.

Source

pub fn class_by_symbol(&self, symbol: &Symbol) -> Option<&Value>

Resolves a class value by symbol.

Source

pub fn function_by_symbol(&self, symbol: &Symbol) -> Option<&Value>

Resolves a function value by symbol.

Source

pub fn macro_by_symbol(&self, symbol: &Symbol) -> Option<&Value>

Resolves a macro value by symbol.

Source

pub fn shape_by_symbol(&self, symbol: &Symbol) -> Option<&Value>

Resolves a shape value by symbol.

Source

pub fn codec_by_symbol(&self, symbol: &Symbol) -> Option<&Value>

Resolves a codec value by symbol.

Source

pub fn number_domain_by_symbol(&self, symbol: &Symbol) -> Option<&Value>

Resolves a number-domain value by symbol.

Source

pub fn site_by_symbol(&self, symbol: &Symbol) -> Option<&Value>

Resolves an opaque site value by symbol.

Source

pub fn manifest_by_symbol(&self, symbol: &Symbol) -> Option<&LibManifest>

Returns the manifest of a loaded library by symbol.

Source

pub fn test_by_symbol(&self, symbol: &Symbol) -> Option<&Arc<dyn Test>>

Returns the test implementation registered under symbol.

Source

pub fn registered_test(&self, symbol: &Symbol) -> Option<&RegisteredTest>

Returns the full RegisteredTest record for symbol.

Source

pub fn value_by_symbol(&self, symbol: &Symbol) -> Option<&Value>

Resolves a plain value export by symbol.

Source

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

Source

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());
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn register_value(&mut self, symbol: Symbol, value: Value) -> Result<()>

Registers a plain value export by symbol; errors on a duplicate value symbol.

Source

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.

Source

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.

Source

pub fn register_number_binary_op(&mut self, op: NumberBinaryOp)

Registers a typed number binary operator.

Source

pub fn register_value_number_binary_op(&mut self, op: ValueNumberBinaryOp)

Registers a value-level number binary operator.

Source

pub fn register_number_unary_op(&mut self, op: NumberUnaryOp)

Registers a typed number unary operator.

Source

pub fn register_value_number_unary_op(&mut self, op: ValueNumberUnaryOp)

Registers a value-level number unary operator.

Source

pub fn register_number_reduction_op(&mut self, op: NumberReductionOp)

Registers a typed number reduction operator.

Source

pub fn register_value_number_reduction_op(&mut self, op: ValueNumberReductionOp)

Registers a value-level number reduction operator.

Source

pub fn register_promotion_rule(&mut self, rule: PromotionRule)

Registers a typed number-domain promotion rule.

Source

pub fn register_value_promotion_rule(&mut self, rule: ValuePromotionRule)

Registers a value-level number-domain promotion rule.

Source

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.

Source

pub fn promotion_rules(&self) -> &[PromotionRule]

All registered typed promotion rules.

Source

pub fn value_promotion_rules(&self) -> &[ValuePromotionRule]

All registered value-level promotion rules.

Source

pub fn number_binary_ops(&self) -> &[NumberBinaryOp]

All registered typed number binary operators.

Source

pub fn value_number_binary_ops(&self) -> &[ValueNumberBinaryOp]

All registered value-level number binary operators.

Source

pub fn number_unary_ops(&self) -> &[NumberUnaryOp]

All registered typed number unary operators.

Source

pub fn value_number_unary_ops(&self) -> &[ValueNumberUnaryOp]

All registered value-level number unary operators.

Source

pub fn number_reduction_ops(&self) -> &[NumberReductionOp]

All registered typed number reduction operators.

Source

pub fn value_number_reduction_ops(&self) -> &[ValueNumberReductionOp]

All registered value-level number reduction operators.

Source

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.

Source

pub fn fresh_lib_id(&mut self) -> LibId

Reserves a fresh stable library id from the catalog sequence.

Source

pub fn fresh_class_id(&mut self) -> ClassId

Reserves a fresh stable class id from the catalog sequence.

Source

pub fn fresh_function_id(&mut self) -> FunctionId

Reserves a fresh stable function id from the catalog sequence.

Source

pub fn fresh_macro_id(&mut self) -> MacroId

Reserves a fresh stable macro id from the catalog sequence.

Source

pub fn fresh_case_id(&mut self) -> CaseId

Reserves a fresh stable case id from the catalog sequence.

Source

pub fn fresh_shape_id(&mut self) -> ShapeId

Reserves a fresh stable shape id from the catalog sequence.

Source

pub fn fresh_codec_id(&mut self) -> CodecId

Reserves a fresh stable codec id from the catalog sequence.

Source

pub fn fresh_number_domain_id(&mut self) -> NumberDomainId

Reserves a fresh stable number-domain id from the catalog sequence.

Source

pub fn fresh_site_id(&mut self) -> SiteId

Reserves a fresh stable site id from the catalog sequence.

Source§

impl Registry

Source

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.

Source

pub fn unload_cascade(&mut self, lib_id: LibId) -> Result<Vec<LibId>>

Unloads a library and its dependents in reverse load order.

Passing an absent id is a no-op and returns an empty list. The returned ids are ordered by the actual unload sequence, with dependents before their dependencies.

Trait Implementations§

Source§

impl Clone for Registry

Source§

fn clone(&self) -> Registry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Registry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.