pub struct IRModule { /* private fields */ }Expand description
A set of functions, each bound to a GlobalVar with a unique name, with the module
attributes attrs and the module-level information global_infos.
A module is mutable: adding, updating or removing functions changes it through every handle to
it, and shallow_copy makes one to change independently.
§Examples
use tvm_tirx::ir::{BaseFunc, DictAttrs, GlobalVar, IRModule, UNKNOWN_LOC};
use tvm_tirx::tvm_ffi::{Map, ObjectRefCore};
let main = GlobalVar::new("main", UNKNOWN_LOC);
let functions = Map::from_iter([(main.clone(), BaseFunc::from(func))]);
let module = IRModule::new(&functions, DictAttrs::new(Map::new()), Map::new())?;
assert!(module.lookup(&main)?.same_as(&module.lookup_name("main")?));Implementations§
Source§impl IRModule
impl IRModule
Sourcepub fn new(
functions: impl Into<Map<GlobalVar, BaseFunc>>,
attrs: impl IntoArg<DictAttrs>,
global_infos: impl Into<Map<String, Array<GlobalInfo>>>,
) -> Result<Self>
pub fn new( functions: impl Into<Map<GlobalVar, BaseFunc>>, attrs: impl IntoArg<DictAttrs>, global_infos: impl Into<Map<String, Array<GlobalInfo>>>, ) -> Result<Self>
Create the module of functions, with the attributes attrs and the module-level
information global_infos, keyed by name.
§Errors
Returns an InternalError if two global variables of functions have the same name.
Sourcepub fn from_expr(
expr: impl IntoExpr,
functions: impl Into<Map<GlobalVar, BaseFunc>>,
) -> Result<Self>
pub fn from_expr( expr: impl IntoExpr, functions: impl Into<Map<GlobalVar, BaseFunc>>, ) -> Result<Self>
Create the module of functions and expr, a function bound to its global_symbol, or to
main (made unique) when it has none (ir.IRModuleFromExpr).
§Errors
Returns a TypeError if expr is not a function.
Sourcepub fn shallow_copy(&self) -> Result<Self>
pub fn shallow_copy(&self) -> Result<Self>
Return a copy of the module that shares its functions (ir.IRModuleClone).
Sourcepub fn add(
&self,
var: impl IntoArg<GlobalVar>,
func: impl IntoArg<BaseFunc>,
update: bool,
) -> Result<()>
pub fn add( &self, var: impl IntoArg<GlobalVar>, func: impl IntoArg<BaseFunc>, update: bool, ) -> Result<()>
Add func as var, replacing an existing definition; the native side currently ignores
update (ir.IRModuleAdd).
§Errors
Returns an InternalError if the module has another global variable of the same name.
Sourcepub fn remove(&self, name: &str) -> Result<()>
pub fn remove(&self, name: &str) -> Result<()>
Remove the function named name (ir.IRModuleRemove).
§Errors
Returns a ValueError if the module has no global variable named name.
Sourcepub fn remove_global_var(&self, var: impl IntoArg<GlobalVar>) -> Result<()>
pub fn remove_global_var(&self, var: impl IntoArg<GlobalVar>) -> Result<()>
Remove the function of var, if the module has one (ir.IRModuleRemove).
Sourcepub fn contains(&self, name: &str) -> Result<bool>
pub fn contains(&self, name: &str) -> Result<bool>
Return whether the module has a global variable named name (ir.IRModuleContains).
Sourcepub fn contains_global_var(&self, var: impl IntoArg<GlobalVar>) -> Result<bool>
pub fn contains_global_var(&self, var: impl IntoArg<GlobalVar>) -> Result<bool>
Return whether the module defines a function for var (ir.IRModuleContains).
Sourcepub fn has_global_var(&self, name: &str) -> Result<bool>
pub fn has_global_var(&self, name: &str) -> Result<bool>
Return whether the module has a global variable named name
(ir.IRModuleContainGlobalVar).
Sourcepub fn get_global_var(&self, name: &str) -> Result<GlobalVar>
pub fn get_global_var(&self, name: &str) -> Result<GlobalVar>
Return the global variable named name (ir.IRModuleGetGlobalVar).
§Errors
Returns a ValueError, which lists the names the module has, if there is none.
Sourcepub fn get_global_vars(&self) -> Result<Array<GlobalVar>>
pub fn get_global_vars(&self) -> Result<Array<GlobalVar>>
Return the global variables of the module, sorted by name (ir.IRModuleGetGlobalVars).
Sourcepub fn lookup(&self, var: impl IntoArg<GlobalVar>) -> Result<BaseFunc>
pub fn lookup(&self, var: impl IntoArg<GlobalVar>) -> Result<BaseFunc>
Return the function of var (ir.IRModuleLookup).
§Errors
Returns an InternalError if the module has no function for var.
Sourcepub fn lookup_name(&self, name: &str) -> Result<BaseFunc>
pub fn lookup_name(&self, name: &str) -> Result<BaseFunc>
Return the function named name (ir.IRModuleLookupStr).
§Errors
Returns a ValueError if the module has no global variable named name.
Sourcepub fn update(&self, other: impl IntoArg<IRModule>) -> Result<()>
pub fn update(&self, other: impl IntoArg<IRModule>) -> Result<()>
Add or replace the functions of other in the module (ir.IRModuleUpdate).
§Errors
Returns an InternalError if a function of other has the name of another global variable
of the module.
Sourcepub fn update_func(
&self,
var: impl IntoArg<GlobalVar>,
func: impl IntoArg<BaseFunc>,
) -> Result<()>
pub fn update_func( &self, var: impl IntoArg<GlobalVar>, func: impl IntoArg<BaseFunc>, ) -> Result<()>
Set the function of var to func (ir.IRModuleUpdateFunction).
§Errors
Returns an InternalError if the module has another global variable of the same name.
Sourcepub fn update_global_info(
&self,
name: &str,
global_info: impl IntoIterator<Item = impl IntoArg<GlobalInfo>>,
) -> Result<()>
pub fn update_global_info( &self, name: &str, global_info: impl IntoIterator<Item = impl IntoArg<GlobalInfo>>, ) -> Result<()>
Set the module-level information name to global_info (ir.IRModuleUpdateGlobalInfo).
Sourcepub fn get_attr(&self, key: &str) -> Result<Option<Any>>
pub fn get_attr(&self, key: &str) -> Result<Option<Any>>
Return the attribute key of the module, or None if it is not set (ir.IRModuleGetAttr).
§Errors
Returns a TypeError if the value is not an object, such as a bool or a short string,
which is stored inline: the native function returns an Optional<ObjectRef>.
Sourcepub fn with_attr(self, key: &str, value: impl Into<Any>) -> Result<IRModule>
pub fn with_attr(self, key: &str, value: impl Into<Any>) -> Result<IRModule>
Return the module with the attribute key set to value (ir.IRModuleWithAttr).
The module is updated in place when this was its only handle, and copied otherwise.
Trait Implementations§
Source§impl DowncastRefFromAny for IRModule
impl DowncastRefFromAny for IRModule
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 IRModule
impl ObjectRefAnyCompatible for IRModule
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 IRModule
impl ObjectRefCore for IRModule
Source§type ContainerType = IRModuleObj
type ContainerType = IRModuleObj
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 IRModule
impl<'a> PackedCallArg for &'a IRModule
Source§impl PackedCallArg for IRModule
impl PackedCallArg for IRModule
impl TypeSubsumes<IRModule> for ObjectRef
Auto Trait Implementations§
impl Freeze for IRModule
impl RefUnwindSafe for IRModule
impl !Send for IRModule
impl !Sync for IRModule
impl Unpin for IRModule
impl UnsafeUnpin for IRModule
impl UnwindSafe for IRModule
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.