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
impl TraceContext
Sourcepub fn input(
&mut self,
spec: ProgramInputSpec,
) -> Result<TraceValue, ProgramBuildError>
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.
Sourcepub fn input_with_default(
&mut self,
spec: ProgramInputSpec,
tensor: Tensor,
) -> Result<TraceValue, ProgramBuildError>
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.
Sourcepub fn bind_input(
&mut self,
input: TraceValue,
tensor: Tensor,
) -> Result<BindingKey, ProgramBuildError>
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.
Sourcepub fn add_op(
&mut self,
op: CoreSemanticOp,
inputs: &[TraceValue],
) -> Result<Box<[TraceValue]>, ProgramBuildError>
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.
Sourcepub fn add_extension(
&mut self,
op: Arc<dyn ExtensionOp>,
inputs: &[TraceValue],
) -> Result<Box<[TraceValue]>, ProgramBuildError>
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.
Sourcepub fn value_metadata(
&self,
value: TraceValue,
) -> Result<&ProgramValueMetadata, ProgramBuildError>
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.
Sourcepub fn extension_caches_mut(&mut self) -> &mut ExtensionCacheStore
pub fn extension_caches_mut(&mut self) -> &mut ExtensionCacheStore
Borrow the generic trace-time extension cache store.
Sourcepub fn finish(
self,
outputs: &[TraceValue],
) -> Result<TracedGraph, ProgramFinishError>
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.