Skip to main content

TraceContext

Struct TraceContext 

Source
pub struct TraceContext { /* private fields */ }
Expand description

Mutable owner of one backend-neutral semantic trace.

Values issued by one context cannot be used by another. Consuming finish freezes the trace into an immutable TracedGraph.

Implementations§

Source§

impl TraceContext

Source

pub fn new() -> Self

Construct an empty trace context.

Source

pub fn input( &mut self, spec: ProgramInputSpec, ) -> Result<TraceValue, ProgramBuildError>

Add one ordered external input.

§Errors

Returns ProgramBuildError::TooManyValues if another value cannot be represented.

Source

pub fn input_with_default( &mut self, spec: ProgramInputSpec, tensor: Tensor, ) -> Result<TraceValue, ProgramBuildError>

Add one ordered input and attach its default tensor.

§Errors

Returns ProgramBuildError::TooManyValues when another input cannot be represented, ProgramBuildError::BindingTargetNotInput if the new value is not accepted as an input, or ProgramBuildError::DuplicateBinding if it is already bound.

Source

pub fn bind_input( &mut self, input: TraceValue, tensor: Tensor, ) -> Result<BindingKey, ProgramBuildError>

Attach a tensor default to an existing trace input.

§Errors

Returns ProgramBuildError::ForeignValue for another context’s value, ProgramBuildError::BindingTargetNotInput for a computed value, or ProgramBuildError::DuplicateBinding for a repeated binding.

Source

pub fn add_op( &mut self, op: CoreSemanticOp, inputs: &[TraceValue], ) -> Result<Box<[TraceValue]>, ProgramBuildError>

Add one canonical core semantic operation.

§Errors

Returns ProgramBuildError::ForeignValue for an input from another context, ProgramBuildError::Arity for the wrong input count, or ProgramBuildError::Metadata / ProgramBuildError::OutputMetadataCount when inference returns invalid metadata.

Source

pub fn add_extension( &mut self, op: Arc<dyn ExtensionOp>, inputs: &[TraceValue], ) -> Result<Box<[TraceValue]>, ProgramBuildError>

Add one extension semantic operation.

§Errors

Returns ProgramBuildError::ForeignValue or ProgramBuildError::Arity for invalid inputs, ProgramBuildError::UndeclaredExtensionEffects / ProgramBuildError::UndeclaredExtensionAliases for an incomplete extension contract, or ProgramBuildError::Metadata when inference fails.

Source

pub fn value_metadata( &self, value: TraceValue, ) -> Result<&ProgramValueMetadata, ProgramBuildError>

Borrow metadata for a context-owned value.

§Errors

Returns ProgramBuildError::ForeignValue for a value from another context.

Source

pub fn extension_caches_mut(&mut self) -> &mut ExtensionCacheStore

Borrow the generic trace-time extension cache store.

Source

pub fn finish( self, outputs: &[TraceValue], ) -> Result<TracedGraph, ProgramFinishError>

Consume and atomically freeze this context.

Ordered and duplicate outputs are preserved.

§Errors

Returns ProgramFinishError::ForeignOutput if an output belongs to another context, or a typed structural/binding finalization failure.

Trait Implementations§

Source§

impl Default for TraceContext

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> 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, 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.