pub struct ConstraintContext { /* private fields */ }Expand description
A context of constraints: the premises in effect at a point of a traversal, ancestors’ first.
Clones share the context’s identity and later appends; use
snapshot to capture the current prefix. A context is neither
Send nor Sync: do not share one across threads, also not through an erased ObjectRef.
§Examples
use tvm_tirx::ir::prim::op::{ge, lt};
use tvm_tirx::ir::{PrimType, PrimVar, Var, UNKNOWN_LOC};
use tvm_tirx::sym::{Analyzer, ConstraintContext, PredicateConstraint, ProofStrength};
let x = PrimVar::new("x", PrimType::int(32), UNKNOWN_LOC);
let outer = ConstraintContext::new();
outer.append(PredicateConstraint::new(ge(&x, 0)?, false))?;
let inner = outer.snapshot();
inner.append(PredicateConstraint::new(lt(&x, 16)?, false))?;
let analyzer = Analyzer::new();
analyzer.sync_constraint_context(&inner)?;
assert!(analyzer.can_prove(lt(&x, 16)?, ProofStrength::Default)?);
analyzer.sync_constraint_context(&outer)?;
assert!(!analyzer.can_prove(lt(&x, 16)?, ProofStrength::Default)?);Implementations§
Source§impl ConstraintContext
impl ConstraintContext
Sourcepub fn with_parent_prefix_size(
parent: impl IntoArg<ConstraintContext>,
parent_prefix_size: i64,
) -> Result<Self>
pub fn with_parent_prefix_size( parent: impl IntoArg<ConstraintContext>, parent_prefix_size: i64, ) -> Result<Self>
Create an empty child that captures the first parent_prefix_size local entries of
parent.
Earlier ancestor prefixes are inherited unchanged; later appends to the parent are excluded.
§Errors
Returns an error if parent_prefix_size is negative or larger than the parent’s local size.
Methods from Deref<Target = ConstraintContextObj>§
Sourcepub fn append(&self, constraint: impl IntoArg<Constraint>) -> Result<()>
pub fn append(&self, constraint: impl IntoArg<Constraint>) -> Result<()>
Append constraint to the local entries (sym.ConstraintContextAppend).
Do not append to the active context of a running native visitor.
Sourcepub fn local_size(&self) -> i64
pub fn local_size(&self) -> i64
Return the number of local entries, excluding captured ancestors.
Sourcepub fn snapshot(&self) -> ConstraintContext
pub fn snapshot(&self) -> ConstraintContext
Capture the visible prefix in an independently extensible child.
Sourcepub fn for_each(&self, callback: impl FnMut(&Constraint))
pub fn for_each(&self, callback: impl FnMut(&Constraint))
Call callback on each visible constraint, in inherited and then local order.
The callback may append without entering this iteration; each borrowed constraint is valid only during its callback.
Sourcepub fn to_array(&self) -> Array<Constraint>
pub fn to_array(&self) -> Array<Constraint>
Return the visible constraints in inherited and then local order, as an independent array.
Later appends do not change it; constraint nodes and expressions remain shared.
Trait Implementations§
Source§impl AsRef<ConstraintContext> for ConstraintContext
impl AsRef<ConstraintContext> for ConstraintContext
Source§impl AsRef<ObjectRef> for ConstraintContext
impl AsRef<ObjectRef> for ConstraintContext
Source§impl Clone for ConstraintContext
impl Clone for ConstraintContext
Source§fn clone(&self) -> ConstraintContext
fn clone(&self) -> ConstraintContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ConstraintContext
impl Debug for ConstraintContext
Source§impl Deref for ConstraintContext
impl Deref for ConstraintContext
Source§impl Display for ConstraintContext
impl Display for ConstraintContext
Source§impl DowncastRefFromAny for ConstraintContext
impl DowncastRefFromAny for ConstraintContext
Source§unsafe fn downcast_ref_from_any(cell: &TVMFFIAny) -> Option<&Self>
unsafe fn downcast_ref_from_any(cell: &TVMFFIAny) -> Option<&Self>
Source§impl From<&ConstraintContext> for ConstraintContext
impl From<&ConstraintContext> for ConstraintContext
Source§fn from(value: &ConstraintContext) -> Self
fn from(value: &ConstraintContext) -> Self
Source§impl From<&ConstraintContext> for ObjectRef
impl From<&ConstraintContext> for ObjectRef
Source§fn from(value: &ConstraintContext) -> Self
fn from(value: &ConstraintContext) -> Self
Source§impl From<ConstraintContext> for ObjectRef
impl From<ConstraintContext> for ObjectRef
Source§fn from(value: ConstraintContext) -> Self
fn from(value: ConstraintContext) -> Self
Source§impl<'a> IntoArg<ConstraintContext> for &'a ConstraintContext
impl<'a> IntoArg<ConstraintContext> for &'a ConstraintContext
Source§type Output = &'a ConstraintContext
type Output = &'a ConstraintContext
T when owned, &T when borrowed.Source§fn into_arg(self) -> &'a ConstraintContext
fn into_arg(self) -> &'a ConstraintContext
T or a &T.Source§fn into_owned(self) -> ConstraintContext
fn into_owned(self) -> ConstraintContext
T, cloning only a borrowed value.Source§impl IntoArg<ConstraintContext> for ConstraintContext
impl IntoArg<ConstraintContext> for ConstraintContext
Source§type Output = ConstraintContext
type Output = ConstraintContext
T when owned, &T when borrowed.Source§fn into_arg(self) -> ConstraintContext
fn into_arg(self) -> ConstraintContext
T or a &T.Source§fn into_owned(self) -> ConstraintContext
fn into_owned(self) -> ConstraintContext
T, cloning only a borrowed value.Source§impl<'a> IntoArg<ObjectRef> for &'a ConstraintContext
impl<'a> IntoArg<ObjectRef> for &'a ConstraintContext
Source§impl IntoArg<ObjectRef> for ConstraintContext
impl IntoArg<ObjectRef> for ConstraintContext
Source§impl ObjectRefAnyCompatible for ConstraintContext
impl ObjectRefAnyCompatible for ConstraintContext
Source§fn extra_check(obj: &Self::ContainerType) -> bool
fn extra_check(obj: &Self::ContainerType) -> bool
obj, an instance of ContainerType, is a value of Self.
Every strict and converting cast checks it, after the object type.Source§fn convert_fallback(value: AnyView<'_>) -> Option<Self>
fn convert_fallback(value: AnyView<'_>) -> Option<Self>
Self object, such as an integer that
stands for a constant; None rejects it. Only converting casts (TryFrom<Any>,
typed function arguments) call it; downcast_ref, downcast and
match_any! never do.Source§fn custom_type_str() -> String
fn custom_type_str() -> String
AnyCompatible::type_str.Source§fn custom_mismatch_type_info(value: AnyView<'_>) -> String
fn custom_mismatch_type_info(value: AnyView<'_>) -> String
value in conversion errors; by default its
runtime type key. See AnyCompatible::get_mismatch_type_info.Source§impl ObjectRefCore for ConstraintContext
impl ObjectRefCore for ConstraintContext
Source§type ContainerType = ConstraintContextObj
type ContainerType = ConstraintContextObj
Source§fn data(this: &Self) -> &ObjectArc<Self::ContainerType>
fn data(this: &Self) -> &ObjectArc<Self::ContainerType>
Source§fn into_data(this: Self) -> ObjectArc<Self::ContainerType>
fn into_data(this: Self) -> ObjectArc<Self::ContainerType>
Source§unsafe fn from_data(data: ObjectArc<Self::ContainerType>) -> Self
unsafe fn from_data(data: ObjectArc<Self::ContainerType>) -> Self
Source§fn same_as<Other>(&self, other: &Other) -> boolwhere
Other: ObjectRefCore,
fn same_as<Other>(&self, other: &Other) -> boolwhere
Other: ObjectRefCore,
Source§fn type_key(&self) -> &'static str
fn type_key(&self) -> &'static str
"ffi.Array", as C++ ObjectRef::GetTypeKey.Source§fn is<T>(&self) -> boolwhere
T: AnyCompatible,
fn is<T>(&self) -> boolwhere
T: AnyCompatible,
T as is, such as a subtype or a container
whose elements are checked too, by the strict check of
downcast, without a reference count change.
See also crate::Any::is.Source§impl<'a> PackedCallArg for &'a ConstraintContext
impl<'a> PackedCallArg for &'a ConstraintContext
Source§type Holder = &'a ConstraintContext
type Holder = &'a ConstraintContext
fn into_packed_arg(self) -> &'a ConstraintContext
fn as_packed_arg(holder: &Self::Holder) -> AnyView<'_>
Source§impl PackedCallArg for ConstraintContext
impl PackedCallArg for ConstraintContext
Source§type Holder = ConstraintContext
type Holder = ConstraintContext
fn into_packed_arg(self) -> ConstraintContext
fn as_packed_arg(holder: &Self::Holder) -> AnyView<'_>
Source§impl<'a> TryFrom<&'a Any> for ConstraintContext
impl<'a> TryFrom<&'a Any> for ConstraintContext
Source§impl TryFrom<&ObjectRef> for ConstraintContext
impl TryFrom<&ObjectRef> for ConstraintContext
Source§impl TryFrom<Any> for ConstraintContext
impl TryFrom<Any> for ConstraintContext
Source§impl<'a> TryFrom<AnyView<'a>> for ConstraintContext
impl<'a> TryFrom<AnyView<'a>> for ConstraintContext
Source§impl TryFrom<ObjectRef> for ConstraintContext
impl TryFrom<ObjectRef> for ConstraintContext
impl TypeSubsumes<ConstraintContext> for ObjectRef
Auto Trait Implementations§
impl Freeze for ConstraintContext
impl !RefUnwindSafe for ConstraintContext
impl !Send for ConstraintContext
impl !Sync for ConstraintContext
impl Unpin for ConstraintContext
impl UnsafeUnpin for ConstraintContext
impl !UnwindSafe for ConstraintContext
Blanket Implementations§
Source§impl<T> AnyCompatible for Twhere
T: ObjectRefAnyCompatible,
impl<T> AnyCompatible for Twhere
T: ObjectRefAnyCompatible,
const MATCH_ANY_EXACT: bool
fn match_any_exact_type_index() -> i32
Source§unsafe fn is_undefined(field: *const T) -> bool
unsafe fn is_undefined(field: *const T) -> bool
field, which holds a value of this type or all-zero bytes,
holds all-zero bytes that are no value of this type, as a null object
reference, a string of type index None or a zero device type: a field
that a creator left undefined for reflection to set. An undefined field
is no value; a nullable reference is Option<T>, whose None is a
defined value. Read moreSource§unsafe fn copy_to_any_view(src: &T, data: &mut TVMFFIAny)
unsafe fn copy_to_any_view(src: &T, data: &mut TVMFFIAny)
Source§unsafe fn move_to_any(src: T, data: &mut TVMFFIAny)
unsafe fn move_to_any(src: T, data: &mut TVMFFIAny)
Source§unsafe fn check_any_strict(data: &TVMFFIAny) -> bool
unsafe fn check_any_strict(data: &TVMFFIAny) -> bool
Source§unsafe fn copy_from_any_view_after_check(data: &TVMFFIAny) -> T
unsafe fn copy_from_any_view_after_check(data: &TVMFFIAny) -> T
Self out of a cell that holds one, retaining any object. Read moreSource§unsafe fn move_from_any_after_check(data: &mut TVMFFIAny) -> T
unsafe fn move_from_any_after_check(data: &mut TVMFFIAny) -> T
Self out of an owning cell that holds one. Read moreSource§unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<T, ()>
unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<T, ()>
data into a Self by the FFI rules, such as an integer into a
float; Err if it does not convert. Read moreSource§fn get_mismatch_type_info(data: &TVMFFIAny) -> String
fn get_mismatch_type_info(data: &TVMFFIAny) -> String
data in conversion errors; by
default its runtime type key.Source§fn type_str() -> String
fn type_str() -> String
int,
ffi.String or Array<int>.Source§fn type_schema() -> String
fn type_schema() -> String
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, S> IntoExpr<T> for S
impl<T, S> IntoExpr<T> for S
Source§type Output = <S as IntoArg<T>>::Output
type Output = <S as IntoArg<T>>::Output
T for an owned value or a literal, or a borrowed &T for a
reference, which converts without a reference-count change. Read moreSource§fn into_expr(self) -> Result<<S as IntoArg<T>>::Output, Error>
fn into_expr(self) -> Result<<S as IntoArg<T>>::Output, Error>
ExprResult raised.Source§fn into_owned_expr(self) -> Result<T>where
Self: Sized,
fn into_owned_expr(self) -> Result<T>where
Self: Sized,
Cow::into_owned
does: an owned value moves, and only a borrowed expression is cloned.