This is an automated email from the ASF dual-hosted git repository.
spectrometerHBH pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-tirx.git
The following commit(s) were added to refs/heads/main by this push:
new 1760c7287 [REFACTOR][RUST] Replace the Placeholder of IR types with
the Unsafeinit (#121)
1760c7287 is described below
commit 1760c7287e76243b37a5aa6b190f64eaf11b24e3
Author: Linzhang Li <[email protected]>
AuthorDate: Thu Oct 29 10:14:52 2026 -0400
[REFACTOR][RUST] Replace the Placeholder of IR types with the Unsafeinit
(#121)
---
3rdparty/tvm-ffi | 2 +-
rust/examples/define_ir.rs | 12 +---
rust/src/ir/attrs.rs | 10 ++++
rust/src/ir/expr.rs | 46 +++++++++++++++
rust/src/ir/function.rs | 12 ++++
rust/src/ir/global_info.rs | 10 ++++
rust/src/ir/location.rs | 10 ++++
rust/src/ir/stmt.rs | 12 ++++
rust/src/ir/type.rs | 12 ++++
rust/src/ir/type_def.rs | 135 ++++++---------------------------------------
rust/src/lib.rs | 16 ++----
rust/src/sym.rs | 10 ++++
rust/tests/ir/op_def.rs | 10 +---
13 files changed, 151 insertions(+), 146 deletions(-)
diff --git a/3rdparty/tvm-ffi b/3rdparty/tvm-ffi
index 1a2e530fa..e9fdc58fa 160000
--- a/3rdparty/tvm-ffi
+++ b/3rdparty/tvm-ffi
@@ -1 +1 @@
-Subproject commit 1a2e530fa68f5a251e3dea8b24d2a7ba19614a14
+Subproject commit e9fdc58fa4bf2e60ed701dacac48a01e41a3dc1f
diff --git a/rust/examples/define_ir.rs b/rust/examples/define_ir.rs
index f582c7179..604b31963 100644
--- a/rust/examples/define_ir.rs
+++ b/rust/examples/define_ir.rs
@@ -31,8 +31,8 @@
use tvm_tirx::ir::op_attr::{CALL_EFFECT_KIND, FIXED_RETURN_TYPE};
use tvm_tirx::ir::sig::{self, IntExpr};
use tvm_tirx::ir::{
- register_type, CallEffectKind, CallObj, DictAttrs, Expr, OpDef,
Placeholder, PrimType, Type,
- TypeObj, Var, UNKNOWN_LOC,
+ register_type, CallEffectKind, CallObj, DictAttrs, Expr, OpDef, PrimType,
Type, TypeObj, Var,
+ UNKNOWN_LOC,
};
use tvm_tirx::tvm_ffi::{self, def_object_ref, rs_class, Array, ObjectRefCast,
Result};
@@ -47,7 +47,7 @@ fn loop_index(call: &CallObj) -> Result<Array<Var>> {
}
// A type, which Python constructs from its fields, `T.ExamplePair(T.int32,
T.float32)`, as it
-// constructs a C++ type. Its object makes the placeholder `__ffi_new__` fills.
+// constructs a C++ type.
/// The type of a pair of values.
#[rs_class("tirx.ExamplePairType", final)]
pub struct ExamplePairTypeObj {
@@ -57,12 +57,6 @@ pub struct ExamplePairTypeObj {
}
def_object_ref!(pub ExamplePairType, Type, ExamplePairTypeObj);
-impl Placeholder for ExamplePairTypeObj {
- fn placeholder() -> Self {
- Self::new(TypeObj::placeholder(), Type::placeholder(),
Type::placeholder())
- }
-}
-
tvm_ffi::static_init_block! {
OpDef::new("tirx.example_clamp", "Clamp an index to the range `[0,
bound)`.")
.signature((
diff --git a/rust/src/ir/attrs.rs b/rust/src/ir/attrs.rs
index a63332cf3..eb301beae 100644
--- a/rust/src/ir/attrs.rs
+++ b/rust/src/ir/attrs.rs
@@ -25,12 +25,14 @@
// tvm-ffi-stubgen(begin): import-section
use std::ops::Deref;
+use std::ptr::addr_of_mut;
use tvm_ffi::Any;
use tvm_ffi::Map;
use tvm_ffi::Object;
use tvm_ffi::ObjectArc;
use tvm_ffi::ShallowCopy;
use tvm_ffi::String;
+use tvm_ffi::UnsafeInit;
// tvm-ffi-stubgen(end)
// tvm-ffi-stubgen(begin): object/ir.Attrs
@@ -80,6 +82,14 @@ impl ShallowCopy for AttrsObj {
Self { base: ShallowCopy::shallow_copy(&self.base) }
}
}
+
+unsafe impl UnsafeInit for AttrsObj {
+ unsafe fn drop_defined_fields(this: *mut Self) {
+ unsafe {
+ UnsafeInit::drop_defined_fields(addr_of_mut!((*this).base));
+ }
+ }
+}
// tvm-ffi-stubgen(end)
// tvm-ffi-stubgen(begin): object/ir.DictAttrs
diff --git a/rust/src/ir/expr.rs b/rust/src/ir/expr.rs
index 21ab5ed75..d42798b85 100644
--- a/rust/src/ir/expr.rs
+++ b/rust/src/ir/expr.rs
@@ -78,6 +78,7 @@ use crate::ir::r#type::TupleTypeObj;
use crate::ir::r#type::Type;
use crate::ir::support;
use std::ops::Deref;
+use std::ptr::addr_of_mut;
use tvm_ffi::Any;
use tvm_ffi::AnyView;
use tvm_ffi::Array;
@@ -89,6 +90,8 @@ use tvm_ffi::ObjectRefCore;
use tvm_ffi::Result;
use tvm_ffi::ShallowCopy;
use tvm_ffi::String;
+use tvm_ffi::UnsafeInit;
+use tvm_ffi::reflection::drop_if_defined;
use tvm_ffi::tvm_ffi_sys::TVMFFITypeIndex;
// tvm-ffi-stubgen(end)
@@ -145,6 +148,16 @@ impl ShallowCopy for ExprObj {
}
}
}
+
+unsafe impl UnsafeInit for ExprObj {
+ unsafe fn drop_defined_fields(this: *mut Self) {
+ unsafe {
+ UnsafeInit::drop_defined_fields(addr_of_mut!((*this).base));
+ drop_if_defined(addr_of_mut!((*this).loc));
+ drop_if_defined(addr_of_mut!((*this).ty));
+ }
+ }
+}
// tvm-ffi-stubgen(end)
/// One index of [`Expr::subscript`]: an expression, or a `start:stop:step`
slice whose missing
@@ -240,6 +253,14 @@ impl ShallowCopy for StagingExprObj {
}
}
+unsafe impl UnsafeInit for StagingExprObj {
+ unsafe fn drop_defined_fields(this: *mut Self) {
+ unsafe {
+ UnsafeInit::drop_defined_fields(addr_of_mut!((*this).base));
+ }
+ }
+}
+
tvm_ffi::impl_object_upcast!(StagingExpr => Expr);
// tvm-ffi-stubgen(end)
@@ -298,6 +319,14 @@ impl ShallowCopy for OpaqueExprObj {
}
}
+unsafe impl UnsafeInit for OpaqueExprObj {
+ unsafe fn drop_defined_fields(this: *mut Self) {
+ unsafe {
+ UnsafeInit::drop_defined_fields(addr_of_mut!((*this).base));
+ }
+ }
+}
+
tvm_ffi::impl_object_upcast!(OpaqueExpr => Expr);
// tvm-ffi-stubgen(end)
@@ -697,6 +726,14 @@ impl ShallowCopy for ConstantObj {
}
}
+unsafe impl UnsafeInit for ConstantObj {
+ unsafe fn drop_defined_fields(this: *mut Self) {
+ unsafe {
+ UnsafeInit::drop_defined_fields(addr_of_mut!((*this).base));
+ }
+ }
+}
+
tvm_ffi::impl_object_upcast!(Constant => Expr);
// tvm-ffi-stubgen(end)
@@ -1589,6 +1626,15 @@ impl ShallowCopy for VarObj {
}
}
+unsafe impl UnsafeInit for VarObj {
+ unsafe fn drop_defined_fields(this: *mut Self) {
+ unsafe {
+ UnsafeInit::drop_defined_fields(addr_of_mut!((*this).base));
+ drop_if_defined(addr_of_mut!((*this).name));
+ }
+ }
+}
+
tvm_ffi::impl_object_upcast!(Var => Expr);
// tvm-ffi-stubgen(end)
diff --git a/rust/src/ir/function.rs b/rust/src/ir/function.rs
index 3d30d0981..1b9446fe1 100644
--- a/rust/src/ir/function.rs
+++ b/rust/src/ir/function.rs
@@ -40,6 +40,7 @@ use crate::ir::expr::ExprObj;
use crate::ir::location::Location;
use crate::ir::r#type::Type;
use std::ops::Deref;
+use std::ptr::addr_of_mut;
use tvm_ffi::Any;
use tvm_ffi::Map;
use tvm_ffi::ObjectArc;
@@ -47,6 +48,8 @@ use tvm_ffi::RValueRef;
use tvm_ffi::Result;
use tvm_ffi::ShallowCopy;
use tvm_ffi::String;
+use tvm_ffi::UnsafeInit;
+use tvm_ffi::reflection::drop_if_defined;
// tvm-ffi-stubgen(end)
// tvm-ffi-stubgen(begin): object/ir.BaseFunc
@@ -105,6 +108,15 @@ impl ShallowCopy for BaseFuncObj {
}
}
+unsafe impl UnsafeInit for BaseFuncObj {
+ unsafe fn drop_defined_fields(this: *mut Self) {
+ unsafe {
+ UnsafeInit::drop_defined_fields(addr_of_mut!((*this).base));
+ drop_if_defined(addr_of_mut!((*this).attrs));
+ }
+ }
+}
+
tvm_ffi::impl_object_upcast!(BaseFunc => Expr);
// tvm-ffi-stubgen(end)
diff --git a/rust/src/ir/global_info.rs b/rust/src/ir/global_info.rs
index 60b088f83..c4815bf20 100644
--- a/rust/src/ir/global_info.rs
+++ b/rust/src/ir/global_info.rs
@@ -25,9 +25,11 @@
// tvm-ffi-stubgen(begin): import-section
use std::ops::Deref;
+use std::ptr::addr_of_mut;
use tvm_ffi::Object;
use tvm_ffi::ObjectArc;
use tvm_ffi::ShallowCopy;
+use tvm_ffi::UnsafeInit;
// tvm-ffi-stubgen(end)
// tvm-ffi-stubgen(begin): object/ir.GlobalInfo
@@ -77,4 +79,12 @@ impl ShallowCopy for GlobalInfoObj {
Self { base: ShallowCopy::shallow_copy(&self.base) }
}
}
+
+unsafe impl UnsafeInit for GlobalInfoObj {
+ unsafe fn drop_defined_fields(this: *mut Self) {
+ unsafe {
+ UnsafeInit::drop_defined_fields(addr_of_mut!((*this).base));
+ }
+ }
+}
// tvm-ffi-stubgen(end)
diff --git a/rust/src/ir/location.rs b/rust/src/ir/location.rs
index a75917c78..3b6147f3b 100644
--- a/rust/src/ir/location.rs
+++ b/rust/src/ir/location.rs
@@ -35,11 +35,13 @@
// tvm-ffi-stubgen(begin): import-section
use crate::ir::support;
use std::ops::Deref;
+use std::ptr::addr_of_mut;
use tvm_ffi::Object;
use tvm_ffi::ObjectArc;
use tvm_ffi::Result;
use tvm_ffi::ShallowCopy;
use tvm_ffi::String;
+use tvm_ffi::UnsafeInit;
// tvm-ffi-stubgen(end)
// tvm-ffi-stubgen(begin): object/ir.SourceName
@@ -141,6 +143,14 @@ impl ShallowCopy for LocationObj {
Self { base: ShallowCopy::shallow_copy(&self.base) }
}
}
+
+unsafe impl UnsafeInit for LocationObj {
+ unsafe fn drop_defined_fields(this: *mut Self) {
+ unsafe {
+ UnsafeInit::drop_defined_fields(addr_of_mut!((*this).base));
+ }
+ }
+}
// tvm-ffi-stubgen(end)
// tvm-ffi-stubgen(begin): object/ir.UnknownLoc
diff --git a/rust/src/ir/stmt.rs b/rust/src/ir/stmt.rs
index 0ec424d39..21a7457f4 100644
--- a/rust/src/ir/stmt.rs
+++ b/rust/src/ir/stmt.rs
@@ -73,6 +73,7 @@ use crate::ir::r#type::PrimType;
use crate::ir::r#type::Type;
use crate::ir::support;
use std::ops::Deref;
+use std::ptr::addr_of_mut;
use tvm_ffi::Any;
use tvm_ffi::AnyView;
use tvm_ffi::Array;
@@ -85,6 +86,8 @@ use tvm_ffi::ObjectRefCore;
use tvm_ffi::Result;
use tvm_ffi::ShallowCopy;
use tvm_ffi::String;
+use tvm_ffi::UnsafeInit;
+use tvm_ffi::reflection::drop_if_defined;
use tvm_ffi::tvm_ffi_sys::TVMFFITypeIndex;
// tvm-ffi-stubgen(end)
@@ -136,6 +139,15 @@ impl ShallowCopy for StmtObj {
Self { base: ShallowCopy::shallow_copy(&self.base), loc:
Clone::clone(&self.loc) }
}
}
+
+unsafe impl UnsafeInit for StmtObj {
+ unsafe fn drop_defined_fields(this: *mut Self) {
+ unsafe {
+ UnsafeInit::drop_defined_fields(addr_of_mut!((*this).base));
+ drop_if_defined(addr_of_mut!((*this).loc));
+ }
+ }
+}
// tvm-ffi-stubgen(end)
// tvm-ffi-stubgen(begin): object/ir.Bind
diff --git a/rust/src/ir/type.rs b/rust/src/ir/type.rs
index e3968d565..651106b48 100644
--- a/rust/src/ir/type.rs
+++ b/rust/src/ir/type.rs
@@ -54,6 +54,7 @@ use crate::ir::location::UnknownLoc;
use crate::ir::support;
use crate::runtime::MemoryScope;
use std::ops::Deref;
+use std::ptr::addr_of_mut;
use tvm_ffi::Array;
use tvm_ffi::DLDataType;
use tvm_ffi::Error;
@@ -62,7 +63,9 @@ use tvm_ffi::ObjectArc;
use tvm_ffi::ObjectRefCore;
use tvm_ffi::Result;
use tvm_ffi::ShallowCopy;
+use tvm_ffi::UnsafeInit;
use tvm_ffi::VALUE_ERROR;
+use tvm_ffi::reflection::drop_if_defined;
// tvm-ffi-stubgen(end)
// tvm-ffi-stubgen(begin): object/ir.Type
@@ -113,6 +116,15 @@ impl ShallowCopy for TypeObj {
Self { base: ShallowCopy::shallow_copy(&self.base), loc:
Clone::clone(&self.loc) }
}
}
+
+unsafe impl UnsafeInit for TypeObj {
+ unsafe fn drop_defined_fields(this: *mut Self) {
+ unsafe {
+ UnsafeInit::drop_defined_fields(addr_of_mut!((*this).base));
+ drop_if_defined(addr_of_mut!((*this).loc));
+ }
+ }
+}
// tvm-ffi-stubgen(end)
// tvm-ffi-stubgen(begin): object/ir.MissingType
diff --git a/rust/src/ir/type_def.rs b/rust/src/ir/type_def.rs
index d68dd4231..295029f0d 100644
--- a/rust/src/ir/type_def.rs
+++ b/rust/src/ir/type_def.rs
@@ -19,111 +19,35 @@
//! Registering IR types from Rust: [`register_type`], which a
[`tvm_ffi::static_init_block!`]
//! calls for an `rs_class` type, as C++ registers a type with
`refl::ObjectDef` in a
-//! `TVM_FFI_STATIC_INIT_BLOCK`, and the [`Placeholder`] values of its fields.
+//! `TVM_FFI_STATIC_INIT_BLOCK`.
//!
-//! `rs_class` registers the fields of a type, but not a way to make one. C++
`refl::ObjectDef`
-//! also registers a creator of an empty object, which tvm-ffi fills through
the reflection of the
-//! fields to construct the type from Python (the `__ffi_init__` it generates)
and to read it from
-//! a JSON graph. A Rust object cannot be empty, as its references are not
null, so
-//! [`register_type`] registers `__ffi_new__`, which makes an object whose
fields hold
-//! [`Placeholder`]s, and tvm-ffi then sets each field as it sets those of a
C++ object.
+//! `rs_class` registers the fields of a type and, as C++ `refl::ObjectDef`
does, a creator of an
+//! object whose fields are undefined, which tvm-ffi fills through the
reflection of the fields to
+//! construct the type from Python (the `__ffi_init__` it generates) and to
read it from a JSON
+//! graph (`__ffi_new__`). [`register_type`] registers the type when its
program or library loads
+//! and exposes its constructor to Python.
-use tvm_ffi::tvm_ffi_sys::{TVMFFIByteArray, TVMFFITypeRegisterAttr};
-use tvm_ffi::{Any, AnyCompatible, Array, Function, ObjectCore, ObjectRefCore,
Result, String};
+use tvm_ffi::{Function, ObjectCore, ObjectRefCore, Result, String};
-use super::expr::{Expr, IntImm};
-use super::location::Location;
-use super::r#type::{MissingType, PrimType, Type, TypeObj};
use super::support;
-/// A valid value of a field type, which an object of a type [`register_type`]
registers holds
-/// until reflection sets the field: `__ffi_new__` makes an object with one in
every field, and a
-/// field `__ffi_init__` does not take (`#[reflect(init_off)]`) keeps it. The
object of a type you
-/// register implements it, from the placeholders of its parent's object and
its fields; this
-/// crate implements it for the common field types, and a field type of your
own crate implements
-/// it too.
-pub trait Placeholder {
- /// The value.
- fn placeholder() -> Self;
-}
-
-macro_rules! default_placeholder {
- ($($ty:ty),*) => {
- $(impl Placeholder for $ty {
- fn placeholder() -> Self {
- Self::default()
- }
- })*
- };
-}
-
-default_placeholder!(bool, i8, i16, i32, i64, u8, u16, u32, u64, f32, f64);
-
-impl Placeholder for String {
- fn placeholder() -> Self {
- String::from("")
- }
-}
-
-impl<T: AnyCompatible + Clone + 'static> Placeholder for Array<T> {
- fn placeholder() -> Self {
- Array::new(vec![])
- }
-}
-
-impl<T> Placeholder for Option<T> {
- fn placeholder() -> Self {
- None
- }
-}
-
-impl Placeholder for Location {
- fn placeholder() -> Self {
- Location::unknown()
- }
-}
-
-impl Placeholder for TypeObj {
- fn placeholder() -> Self {
- TypeObj::new(Location::unknown())
- }
-}
-
-impl Placeholder for Type {
- fn placeholder() -> Self {
- MissingType::new().into()
- }
-}
-
-impl Placeholder for PrimType {
- fn placeholder() -> Self {
- PrimType::void()
- }
-}
-
-impl Placeholder for Expr {
- fn placeholder() -> Self {
- IntImm::new(Location::unknown(), PrimType::int(32), 0).into()
- }
-}
-
/// Register the IR type of the reference `R`, an `rs_class` type, as C++
registers one with
-/// `refl::ObjectDef`: `__ffi_new__`, from the [`Placeholder`] of the object,
then the
-/// `__ffi_init__` tvm-ffi generates from the reflected fields, then, when the
receiver is
-/// installed, a request for its constructor in registered destinations
(`ir.expose_type`); an
-/// absent receiver is a no-op, and an installed receiver's error is returned.
With an explicitly
-/// declared `my_ext` type API destination, Python then constructs the type
from its fields,
-/// `my_ext.Pair(T.int32, second=T.float32)`, as it constructs a C++ type, and
a JSON graph holds
-/// it. Import `tvm_tirx` before loading the library so exposure requests
reach Python. Import the
-/// extension module in Python scope, or supply it to text parsing through
imports, `extra_vars` or
-/// explicit parser namespace registration; type exposure does not add parser
defaults.
+/// `refl::ObjectDef`: the type, with the `__ffi_new__` and `__ffi_init__`
`rs_class` registers,
+/// then, when the receiver is installed, a request for its constructor in
registered destinations
+/// (`ir.expose_type`); an absent receiver is a no-op, and an installed
receiver's error is
+/// returned. With an explicitly declared `my_ext` type API destination,
Python then constructs the
+/// type from its fields, `my_ext.Pair(T.int32, second=T.float32)`, as it
constructs a C++ type, and
+/// a JSON graph holds it. Import `tvm_tirx` before loading the library so
exposure requests reach
+/// Python. Import the extension module in Python scope, or supply it to text
parsing through
+/// imports, `extra_vars` or explicit parser namespace registration; type
exposure does not add
+/// parser defaults.
///
/// Call it in a [`tvm_ffi::static_init_block!`], with the
[`OpDef`](crate::ir::OpDef) chains of
/// the operators, so that the type is registered when its program or library
loads, as a C++ one
/// is; the type's struct, reference and `impl`s are written outside the
block, as any other:
///
/// ```no_run
-/// use tvm_tirx::ir::{register_type, Location, Placeholder, Type, TypeObj};
+/// use tvm_tirx::ir::{register_type, Location, Type, TypeObj};
/// use tvm_tirx::tvm_ffi::{self, def_object_ref, rs_class, ObjectRefCore};
///
/// /// The type of a pair of values, printed as `my_ext.Pair(first, second)`.
@@ -136,12 +60,6 @@ impl Placeholder for Expr {
/// }
/// def_object_ref!(pub PairType, Type, PairTypeObj);
///
-/// impl Placeholder for PairTypeObj {
-/// fn placeholder() -> Self {
-/// Self::new(TypeObj::placeholder(), Type::placeholder(),
Type::placeholder())
-/// }
-/// }
-///
/// impl PairType {
/// pub fn new(first: impl Into<Type>, second: impl Into<Type>) -> Self {
/// PairTypeObj::new(TypeObj::new(Location::unknown()), first,
second).into()
@@ -152,27 +70,10 @@ impl Placeholder for Expr {
/// register_type::<PairType>()?;
/// }
/// ```
-pub fn register_type<R>() -> Result<()>
-where
- R: ObjectRefCore + AnyCompatible + From<R::ContainerType> + 'static,
- R::ContainerType: Placeholder,
-{
+pub fn register_type<R: ObjectRefCore>() -> Result<()> {
let type_index = R::ContainerType::type_index();
- let new =
- Function::from_typed(|| -> Result<R> {
Ok(R::from(R::ContainerType::placeholder())) });
- register_type_attr(type_index, "__ffi_new__", Any::from(new))?;
-
tvm_ffi::cached_global_func!("ffi._RegisterFFIInit").call_tuple((type_index,))?;
if let Ok(expose) = Function::get_global("ir.expose_type") {
expose.call_tuple((String::from(support::type_key(type_index).as_str()),))?;
}
Ok(())
}
-
-/// Register `value` as the type attribute `name` of the type of `type_index`.
-fn register_type_attr(type_index: i32, name: &str, mut value: Any) ->
Result<()> {
- // SAFETY: `name` and `value` outlive the call, which copies them.
- let name = unsafe { TVMFFIByteArray::from_str(name) };
- tvm_ffi::check_safe_call!(unsafe {
- TVMFFITypeRegisterAttr(type_index, &name, Any::as_data_ptr(&mut value))
- })
-}
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 30ef5250d..344b1ab51 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -112,16 +112,11 @@
//! use tvm_tirx::ir::sig::{self, IntExpr};
//! use tvm_tirx::ir::{register_type, CallEffectKind, CallObj, OpDef,
OpHandle, Type};
//! use tvm_tirx::tvm_ffi::{self, Result};
-//! # use tvm_tirx::ir::{Placeholder, TypeObj};
+//! # use tvm_tirx::ir::TypeObj;
//! # use tvm_tirx::tvm_ffi::{def_object_ref, rs_class, ObjectRefCore};
//! # #[rs_class("my_ext.PairType", final)]
//! # pub struct PairTypeObj { base: TypeObj, pub first: Type, pub second:
Type }
//! # def_object_ref!(pub PairType, Type, PairTypeObj);
-//! # impl Placeholder for PairTypeObj {
-//! # fn placeholder() -> Self {
-//! # Self::new(TypeObj::placeholder(), Type::placeholder(),
Type::placeholder())
-//! # }
-//! # }
//!
//! fn index_type(call: &CallObj) -> Result<Type> {
//! Ok(call.args.get(0)?.ty.clone())
@@ -214,11 +209,10 @@
//!
//! The generated code names `tvm_ffi`, which `use tvm_tirx::tvm_ffi` brings
into scope in a crate
//! that depends only on `tvm-tirx`. The parent's object must have a public
`new` and implement
-//! `ShallowCopy`; the bindings generate both for a complete type that is not
final, as `ir.Type`.
-//! Registered by [`ir::register_type`] in a [`tvm_ffi::static_init_block!`],
with the operators,
-//! the type is also constructed by Python from its fields and parsed by
TVMScript, as a C++ type;
-//! its object must implement [`ir::Placeholder`], written from the
placeholders of the parent's
-//! object and the fields.
+//! `ShallowCopy` and `UnsafeInit`; the bindings generate them for a complete
type that is not
+//! final, as `ir.Type`. Registered by [`ir::register_type`] in a
[`tvm_ffi::static_init_block!`],
+//! with the operators, the type is also constructed by Python from its fields
and parsed by
+//! TVMScript, as a C++ type.
//!
//! # Generated and hand-written code
//!
diff --git a/rust/src/sym.rs b/rust/src/sym.rs
index 076b2ebeb..426055685 100644
--- a/rust/src/sym.rs
+++ b/rust/src/sym.rs
@@ -41,9 +41,11 @@ use crate::ir::expr::Expr;
use crate::ir::expr::Range;
use crate::ir::expr::Var;
use std::ops::Deref;
+use std::ptr::addr_of_mut;
use tvm_ffi::Object;
use tvm_ffi::ObjectArc;
use tvm_ffi::ShallowCopy;
+use tvm_ffi::UnsafeInit;
// tvm-ffi-stubgen(end)
// tvm-ffi-stubgen(begin): object/sym.Constraint
@@ -93,6 +95,14 @@ impl ShallowCopy for ConstraintObj {
Self { base: ShallowCopy::shallow_copy(&self.base) }
}
}
+
+unsafe impl UnsafeInit for ConstraintObj {
+ unsafe fn drop_defined_fields(this: *mut Self) {
+ unsafe {
+ UnsafeInit::drop_defined_fields(addr_of_mut!((*this).base));
+ }
+ }
+}
// tvm-ffi-stubgen(end)
// tvm-ffi-stubgen(begin): object/sym.BindingConstraint
diff --git a/rust/tests/ir/op_def.rs b/rust/tests/ir/op_def.rs
index c50390505..80d981346 100644
--- a/rust/tests/ir/op_def.rs
+++ b/rust/tests/ir/op_def.rs
@@ -32,8 +32,8 @@ use tvm_tirx::ir::op_attr::{CALL_EFFECT_KIND,
FIXED_RETURN_TYPE};
use tvm_tirx::ir::sig::{self, IntExpr, PrimExpr, PrimVar};
use tvm_tirx::ir::{
register_type, AttrKey, Attrs, Call, CallEffectKind, CallObj, DictAttrs,
Evaluate, Expr,
- FuncType, IntImm, Op, OpDef, OpHandle, Placeholder, PrimType, RegionStmt,
RegionStmtObj,
- StringImm, Type, TypeObj, Var, VarObj, UNKNOWN_LOC,
+ FuncType, IntImm, Op, OpDef, OpHandle, PrimType, RegionStmt,
RegionStmtObj, StringImm, Type,
+ TypeObj, Var, VarObj, UNKNOWN_LOC,
};
use tvm_tirx::tirx::{CallFFIKernelAttr, TensorVar};
use tvm_tirx::tvm_ffi::static_init::{StaticInitBlock, STATIC_INIT_BLOCKS};
@@ -424,12 +424,6 @@ pub struct BlockTypeObj {
}
def_object_ref!(pub BlockType, Type, BlockTypeObj);
-impl Placeholder for BlockTypeObj {
- fn placeholder() -> Self {
- Self::new(TypeObj::placeholder(), Type::placeholder(),
i64::placeholder())
- }
-}
-
tvm_ffi::static_init_block! {
OpDef::new("rust_test.defined_identity", "
Return the value.