pub struct Analyzer { /* private fields */ }Expand description
An analyzer of integer expressions: it proves, bounds and simplifies them under the facts it
knows, which sync_constraint_context sets from a
ConstraintContext.
A clone shares the analyzer and its facts; deep_clone copies them.
When the build includes the Z3 prover, default-strength proofs fall back to it unless
set_z3_default_fallback turns that off.
§Examples
use tvm_tirx::ir::prim::op::floordiv;
use tvm_tirx::ir::{PrimType, PrimVar, Range, Var, UNKNOWN_LOC};
use tvm_tirx::script::script;
use tvm_tirx::sym::{Analyzer, ConstraintContext, RangeConstraint};
let x = PrimVar::new("x", PrimType::int(32), UNKNOWN_LOC);
let context = ConstraintContext::new();
let domain = Range::from_min_extent(0, 16, UNKNOWN_LOC)?;
context.append(RangeConstraint::new(x.clone(), domain))?;
let analyzer = Analyzer::new();
analyzer.sync_constraint_context(&context)?;
assert_eq!(script(&analyzer.simplify(floordiv(&x, 16)?, 2)?)?, "0");
assert_eq!(script(&Analyzer::new().simplify(floordiv(&x, 16)?, 2)?)?, "x // 16");Implementations§
Source§impl Analyzer
impl Analyzer
Sourcepub fn set_z3_default_fallback(&self, enabled: bool) -> Result<()>
pub fn set_z3_default_fallback(&self, enabled: bool) -> Result<()>
Set whether default-strength queries try Z3 after native analysis fails
(sym.AnalyzerSetZ3DefaultFallback).
Enabled by default and preserved by deep_clone. Stronger queries and
direct Z3 APIs are unaffected. This does not clear accepted premises or solver state.
Sourcepub fn deep_clone(&self) -> Result<Self>
pub fn deep_clone(&self) -> Result<Self>
Return a copy of the analyzer and the facts it knows, which learns facts independently
(sym.AnalyzerClone).
Sourcepub fn sync_constraint_context(
&self,
context: impl IntoArg<ConstraintContext>,
) -> Result<()>
pub fn sync_constraint_context( &self, context: impl IntoArg<ConstraintContext>, ) -> Result<()>
Synchronize the analyzer’s facts with context at its current position
(sym.AnalyzerSyncConstraintContext).
Later appends to the context take effect only at the next synchronization.
§Errors
Returns an error for a reentrant synchronization, or if context defines a variable twice.
Sourcepub fn get_constraint_context(&self) -> Result<ConstraintContext>
pub fn get_constraint_context(&self) -> Result<ConstraintContext>
Snapshot the accepted premises in an independently extensible context
(sym.AnalyzerGetConstraintContext).
Fact and expression nodes remain shared. Appending to this context changes the analyzer only
after sync_constraint_context is called again.
Sourcepub fn const_int_bound(
&self,
expr: impl IntoExpr<PrimExpr>,
) -> Result<ConstIntBound>
pub fn const_int_bound( &self, expr: impl IntoExpr<PrimExpr>, ) -> Result<ConstIntBound>
Return the constant bounds of expr under the known facts (sym.AnalyzerConstIntBound).
Sourcepub fn const_int_bound_is_bound(&self, var: impl IntoArg<Var>) -> Result<bool>
pub fn const_int_bound_is_bound(&self, var: impl IntoArg<Var>) -> Result<bool>
Return whether var has constant bounds recorded (sym.AnalyzerConstIntBoundIsBound).
Sourcepub fn modular_set(&self, expr: impl IntoExpr<PrimExpr>) -> Result<ModularSet>
pub fn modular_set(&self, expr: impl IntoExpr<PrimExpr>) -> Result<ModularSet>
Return the modular set coeff * x + base of expr (sym.AnalyzerModularSet).
Sourcepub fn int_set(
&self,
expr: impl IntoExpr<PrimExpr>,
dom_map: impl Into<Option<Map<Var, IntSet>>>,
) -> Result<IntSet>
pub fn int_set( &self, expr: impl IntoExpr<PrimExpr>, dom_map: impl Into<Option<Map<Var, IntSet>>>, ) -> Result<IntSet>
Return the integer set expr covers, with the variables of dom_map over their sets
(sym.AnalyzerIntSet).
Sourcepub fn simplify(
&self,
expr: impl IntoExpr<PrimExpr>,
steps: i32,
) -> Result<PrimExpr>
pub fn simplify( &self, expr: impl IntoExpr<PrimExpr>, steps: i32, ) -> Result<PrimExpr>
Simplify expr, alternating the rewrite and canonical simplifiers steps times
(sym.AnalyzerSimplify).
Sourcepub fn rewrite_simplify(
&self,
expr: impl IntoExpr<PrimExpr>,
) -> Result<PrimExpr>
pub fn rewrite_simplify( &self, expr: impl IntoExpr<PrimExpr>, ) -> Result<PrimExpr>
Simplify expr by rewrite rules (sym.AnalyzerRewriteSimplify).
Sourcepub fn canonical_simplify(
&self,
expr: impl IntoExpr<PrimExpr>,
) -> Result<PrimExpr>
pub fn canonical_simplify( &self, expr: impl IntoExpr<PrimExpr>, ) -> Result<PrimExpr>
Simplify expr into canonical form (sym.AnalyzerCanonicalSimplify).
Sourcepub fn rewrite_simplify_stats(&self) -> Result<RewriteSimplifierStats>
pub fn rewrite_simplify_stats(&self) -> Result<RewriteSimplifierStats>
Return the counters of the rewrite simplifier (sym.AnalyzerGetRewriteSimplifyStats).
Sourcepub fn reset_rewrite_simplify_stats(&self) -> Result<()>
pub fn reset_rewrite_simplify_stats(&self) -> Result<()>
Zero the counters of the rewrite simplifier (sym.AnalyzerResetRewriteSimplifyStats).
Sourcepub fn set_maximum_rewrite_steps(&self, maximum: i64) -> Result<()>
pub fn set_maximum_rewrite_steps(&self, maximum: i64) -> Result<()>
Cap the rewrites of one rewrite simplification at maximum, or 0 for no cap
(sym.AnalyzerSetMaximumRewriteSteps).
Sourcepub fn can_prove(
&self,
expr: impl IntoExpr<PrimExpr>,
strength: ProofStrength,
) -> Result<bool>
pub fn can_prove( &self, expr: impl IntoExpr<PrimExpr>, strength: ProofStrength, ) -> Result<bool>
Return whether expr is provably true (sym.AnalyzerCanProve).
Sourcepub fn can_prove_equal(
&self,
lhs: impl IntoExpr<PrimExpr>,
rhs: impl IntoExpr<PrimExpr>,
) -> Result<bool>
pub fn can_prove_equal( &self, lhs: impl IntoExpr<PrimExpr>, rhs: impl IntoExpr<PrimExpr>, ) -> Result<bool>
Return whether lhs == rhs is provably true (sym.AnalyzerCanProveEqual).
Sourcepub fn try_compare(
&self,
lhs: impl IntoExpr<PrimExpr>,
rhs: impl IntoExpr<PrimExpr>,
) -> Result<CompareResult>
pub fn try_compare( &self, lhs: impl IntoExpr<PrimExpr>, rhs: impl IntoExpr<PrimExpr>, ) -> Result<CompareResult>
Return the relation of lhs to rhs that the known comparisons imply
(sym.AnalyzerTryCompare).
Sourcepub fn is_z3_enabled(&self) -> Result<bool>
pub fn is_z3_enabled(&self) -> Result<bool>
Return whether TIRx was built with the Z3 prover (sym.AnalyzerIsZ3Enabled).
Sourcepub fn smtlib2(&self, expr: Option<&PrimExpr>) -> Result<String>
pub fn smtlib2(&self, expr: Option<&PrimExpr>) -> Result<String>
Return the facts the Z3 prover knows, and expr to prove if given, as an SMT-LIB2 script
(sym.AnalyzerGetSMTLIB2).
Sourcepub fn set_z3_timeout_ms(&self, timeout_ms: u32) -> Result<()>
pub fn set_z3_timeout_ms(&self, timeout_ms: u32) -> Result<()>
Bound each Z3 proof by timeout_ms milliseconds (sym.AnalyzerSetZ3TimeoutMs).
Sourcepub fn set_z3_rlimit(&self, rlimit: u32) -> Result<()>
pub fn set_z3_rlimit(&self, rlimit: u32) -> Result<()>
Bound each Z3 proof by the resource limit rlimit (sym.AnalyzerSetZ3RLimit).
Trait Implementations§
Source§impl DowncastRefFromAny for Analyzer
impl DowncastRefFromAny for Analyzer
Source§unsafe fn downcast_ref_from_any(cell: &TVMFFIAny) -> Option<&Self>
unsafe fn downcast_ref_from_any(cell: &TVMFFIAny) -> Option<&Self>
Source§impl ObjectRefAnyCompatible for Analyzer
impl ObjectRefAnyCompatible for Analyzer
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 Analyzer
impl ObjectRefCore for Analyzer
Source§type ContainerType = AnalyzerObj
type ContainerType = AnalyzerObj
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 Analyzer
impl<'a> PackedCallArg for &'a Analyzer
Source§impl PackedCallArg for Analyzer
impl PackedCallArg for Analyzer
impl TypeSubsumes<Analyzer> for ObjectRef
Auto Trait Implementations§
impl Freeze for Analyzer
impl RefUnwindSafe for Analyzer
impl !Send for Analyzer
impl !Sync for Analyzer
impl Unpin for Analyzer
impl UnsafeUnpin for Analyzer
impl UnwindSafe for Analyzer
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.