-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Rust][IRModule] Flesh out IRModule methods #6741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
57c72f5
7a5869e
b2d0095
b784534
a39a1bf
3e8cd8e
1b72ca0
fdaa4af
726a01b
79275b3
6875ac7
da2ab07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,10 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> TokenStream { | |
| .map(attr_to_str) | ||
| .expect("Failed to get type_key"); | ||
|
|
||
| let derive = get_attr(&derive_input, "no_derive") | ||
| .map(|_| false) | ||
| .unwrap_or(true); | ||
|
|
||
| let ref_id = get_attr(&derive_input, "ref_name") | ||
| .map(|a| Ident::new(attr_to_str(a).value().as_str(), Span::call_site())) | ||
| .unwrap_or_else(|| { | ||
|
|
@@ -75,6 +79,12 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> TokenStream { | |
| _ => panic!("derive only works for structs"), | ||
| }; | ||
|
|
||
| let ref_derives = if derive { | ||
jroesch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| quote! { #[derive(Debug, Clone)]} | ||
| } else { | ||
| quote! { #[derive(Clone)] } | ||
| }; | ||
|
|
||
| let mut expanded = quote! { | ||
| unsafe impl #tvm_rt_crate::object::IsObject for #payload_id { | ||
| const TYPE_KEY: &'static str = #type_key; | ||
|
|
@@ -87,7 +97,7 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> TokenStream { | |
| } | ||
| } | ||
|
|
||
| #[derive(Clone)] | ||
| #ref_derives | ||
| pub struct #ref_id(Option<#tvm_rt_crate::object::ObjectPtr<#payload_id>>); | ||
|
|
||
| impl #tvm_rt_crate::object::IsObjectRef for #ref_id { | ||
|
|
@@ -185,5 +195,25 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> TokenStream { | |
|
|
||
| expanded.extend(base_tokens); | ||
|
|
||
| if derive { | ||
| let derives = quote! { | ||
| impl std::hash::Hash for #ref_id { | ||
| fn hash<H: std::hash::Hasher>(&self, state: &mut H) { | ||
| self.0.hash(state) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly dumb comment (I'm not familiar with this macro) - is
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No we generate a wrapper new type over the ObjectPtr which contains 1 field always. ObjectPtr is currently dispatching to TVM's C++ hashing so we have cross language consistency. |
||
| } | ||
| } | ||
|
|
||
| impl std::cmp::PartialEq for #ref_id { | ||
| fn eq(&self, other: &Self) -> bool { | ||
| self.0 == other.0 | ||
| } | ||
| } | ||
|
|
||
| impl std::cmp::Eq for #ref_id {} | ||
| }; | ||
|
|
||
| expanded.extend(derives); | ||
| } | ||
|
|
||
| TokenStream::from(expanded) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: brief rustdoc? Some comments would help me get the story of what
ExternalItemandExternalare for.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What Greg said