From d601af014e7c9d1688eca12329b8c3104cd1527a Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 09:47:54 +0800 Subject: [PATCH 01/14] feat: mode --- frb_codegen/src/library/codegen/ir/mir/skip.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frb_codegen/src/library/codegen/ir/mir/skip.rs b/frb_codegen/src/library/codegen/ir/mir/skip.rs index 6328a98937..ea1497c6b3 100644 --- a/frb_codegen/src/library/codegen/ir/mir/skip.rs +++ b/frb_codegen/src/library/codegen/ir/mir/skip.rs @@ -9,6 +9,7 @@ pub struct MirSkip { #[derive(Copy, PartialOrd, Ord)] pub(crate) enum MirSkipReason { IgnoredFunctionNotPub, + IgnoredFunctionGeneric, IgnoredTypeNotUsedByPub, IgnoredMisc, Err, @@ -21,6 +22,9 @@ impl MirSkipReason { Self::IgnoredFunctionNotPub => { "These functions are ignored because they are not marked as `pub`" } + Self::IgnoredFunctionGeneric => { + "These functions are ignored because they have generic arguments" + } Self::IgnoredTypeNotUsedByPub => { "These types are ignored because they are not used by any `pub` functions" } From 9cf2a6a99e895a5f920f3bce870a83968c34a44d Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 09:48:08 +0800 Subject: [PATCH 02/14] feat: more --- .../src/library/codegen/parser/mir/function_parser/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs index 895ef1f2b4..26bd18c7f0 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs @@ -21,6 +21,7 @@ use std::fmt::Debug; use syn::*; use MirSkipReason::{IgnoredFunctionNotPub, IgnoredMisc}; use MirType::Primitive; +use crate::codegen::ir::mir::skip::MirSkipReason::IgnoredFunctionGeneric; pub(crate) mod argument; pub(crate) mod output; @@ -80,6 +81,13 @@ impl<'a, 'b> FunctionParser<'a, 'b> { IgnoredFunctionNotPub, )); } + if TODO { + return Ok(create_output_skip( + func, + namespace_naive, + IgnoredFunctionGeneric, + )); + } let src_lineno = func.span().start().line; let attributes = FrbAttributes::parse(func.attrs())?; From 551f792c785169dd9143742f8dc730c350e5bfa2 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 09:49:16 +0800 Subject: [PATCH 03/14] feat: impl --- .../src/library/codegen/parser/mir/function_parser/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs index 26bd18c7f0..122ccf3b4b 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs @@ -4,6 +4,7 @@ use crate::codegen::ir::mir::func::{ MirFunc, MirFuncArgMode, MirFuncInput, MirFuncMode, MirFuncOutput, MirFuncOwnerInfo, MirFuncOwnerInfoMethod, MirFuncOwnerInfoMethodMode, }; +use crate::codegen::ir::mir::skip::MirSkipReason::IgnoredFunctionGeneric; use crate::codegen::ir::mir::skip::{MirSkip, MirSkipReason}; use crate::codegen::ir::mir::ty::primitive::MirTypePrimitive; use crate::codegen::ir::mir::ty::rust_opaque::RustOpaqueCodecMode; @@ -21,7 +22,6 @@ use std::fmt::Debug; use syn::*; use MirSkipReason::{IgnoredFunctionNotPub, IgnoredMisc}; use MirType::Primitive; -use crate::codegen::ir::mir::skip::MirSkipReason::IgnoredFunctionGeneric; pub(crate) mod argument; pub(crate) mod output; @@ -81,7 +81,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> { IgnoredFunctionNotPub, )); } - if TODO { + if !func.sig().generics.params.is_empty() { return Ok(create_output_skip( func, namespace_naive, From 8a202c22315d10a3a79a6d40a47fd1ef07c85d84 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 09:56:19 +0800 Subject: [PATCH 04/14] chore: empty --- frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs index 0ce76f9339..0f5920f373 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs @@ -58,4 +58,5 @@ pub(crate) fn parse_type_should_ignore_simple( // For third party crates, if a struct is not public, then it is impossible to utilize it, // thus we ignore it. || (crate_name != &CrateName::self_crate() && vis != HirVisibility::Public) + || TODO } From 1d36b0d13c2c2e8c104f132e55f6f43617c96a1f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 09:58:57 +0800 Subject: [PATCH 05/14] feat: more --- .../library/codegen/parser/mir/type_parser/misc.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs index 0f5920f373..fe62810f4f 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs @@ -1,4 +1,6 @@ use crate::codegen::ir::hir::hierarchical::module::HirVisibility; +use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStructOrEnum; +use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStructOrEnum; use crate::codegen::ir::mir::comment::MirComment; use crate::codegen::parser::mir::attribute_parser::FrbAttributes; use crate::utils::crate_name::CrateName; @@ -49,14 +51,16 @@ fn parse_comment(input: &str) -> MirComment { }) } -pub(crate) fn parse_type_should_ignore_simple( - attrs: &FrbAttributes, - vis: HirVisibility, +// TODO rename +pub(crate) fn parse_type_should_ignore_simple( + src_object: HirStructOrEnum, crate_name: &CrateName, ) -> bool { + let attrs = FrbAttributes::parse(src_object.src.attrs())?; + attrs.ignore() // For third party crates, if a struct is not public, then it is impossible to utilize it, // thus we ignore it. - || (crate_name != &CrateName::self_crate() && vis != HirVisibility::Public) + || (crate_name != &CrateName::self_crate() && src_object.visibility != HirVisibility::Public) || TODO } From 2b668a572279d3b209393efcb63a14c7a17478ec Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 09:59:35 +0800 Subject: [PATCH 06/14] feat: more --- .../codegen/parser/mir/type_parser/enum_or_struct.rs | 8 +++----- .../library/codegen/parser/mir/type_parser/enumeration.rs | 6 +----- .../library/codegen/parser/mir/type_parser/structure.rs | 6 +----- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs index 18f5412ce2..d0d097f0ed 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs @@ -99,18 +99,16 @@ where } } - fn parse_opaque( + fn parse_opaque( &mut self, namespaced_name: &NamespacedName, - attrs: &FrbAttributes, - vis: HirVisibility, + src_object: HirStructOrEnum, ) -> anyhow::Result { self.parse_type_rust_auto_opaque_implicit( Some(namespaced_name.namespace.clone()), &syn::parse_str(&namespaced_name.name)?, Some(parse_type_should_ignore_simple( - attrs, - vis, + src_object, &namespaced_name.namespace.crate_name(), )), ) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs index 17d3f006e0..ef2ce484f4 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs @@ -51,11 +51,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { let mode = compute_enum_mode(&raw_variants); let variants = maybe_field_wrap_box(raw_variants, mode); - let ignore = parse_type_should_ignore_simple( - &attributes, - src_enum.visibility, - &name.namespace.crate_name(), - ); + let ignore = parse_type_should_ignore_simple(src_enum, &name.namespace.crate_name()); Ok(MirEnum { name, diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs index 1a64ab2fcf..fd15f46d8d 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs @@ -53,11 +53,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { let attributes = FrbAttributes::parse(&src_struct.src.attrs)?; let dart_metadata = attributes.dart_metadata(); - let ignore = parse_type_should_ignore_simple( - &attributes, - src_struct.visibility, - &name.namespace.crate_name(), - ); + let ignore = parse_type_should_ignore_simple(src_struct, &name.namespace.crate_name()); Ok(MirStruct { name, From 41dadc849adb1a23754f946eb7a7d119d76fc880 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 10:00:16 +0800 Subject: [PATCH 07/14] fix: err --- .../codegen/parser/mir/type_parser/enum_or_struct.rs | 8 ++++---- .../src/library/codegen/parser/mir/type_parser/misc.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs index d0d097f0ed..8c51d77094 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs @@ -47,7 +47,7 @@ where if attrs_opaque == Some(true) { debug!("Treat {name} as opaque since attribute says so"); return Ok(Some(( - self.parse_opaque(&namespaced_name, &attrs, vis)?, + self.parse_opaque(&namespaced_name, &src_object)?, attrs, ))); } @@ -70,7 +70,7 @@ where { debug!("Treat {name} as opaque by compute_default_opaque"); return Ok(Some(( - self.parse_opaque(&namespaced_name, &attrs, vis)?, + self.parse_opaque(&namespaced_name, &src_object)?, attrs, ))); } @@ -99,10 +99,10 @@ where } } - fn parse_opaque( + fn parse_opaque( &mut self, namespaced_name: &NamespacedName, - src_object: HirStructOrEnum, + src_object: &HirStructOrEnum, ) -> anyhow::Result { self.parse_type_rust_auto_opaque_implicit( Some(namespaced_name.namespace.clone()), diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs index fe62810f4f..4d5c89ac24 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs @@ -53,10 +53,10 @@ fn parse_comment(input: &str) -> MirComment { // TODO rename pub(crate) fn parse_type_should_ignore_simple( - src_object: HirStructOrEnum, + src_object: &HirStructOrEnum, crate_name: &CrateName, ) -> bool { - let attrs = FrbAttributes::parse(src_object.src.attrs())?; + let attrs = FrbAttributes::parse(src_object.src.attrs()).unwrap(); attrs.ignore() // For third party crates, if a struct is not public, then it is impossible to utilize it, From 4f5a13b8559d8fd186970387014afa4c2792c6bd Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 10:00:35 +0800 Subject: [PATCH 08/14] refctor: mv --- .../parser/mir/type_parser/enum_or_struct.rs | 16 +++++++++++++++- .../parser/mir/type_parser/enumeration.rs | 6 ++---- .../codegen/parser/mir/type_parser/misc.rs | 14 -------------- .../codegen/parser/mir/type_parser/structure.rs | 6 ++---- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs index 8c51d77094..ec816c6193 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs @@ -3,9 +3,9 @@ use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStructOrEnum; use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStructOrEnum; use crate::codegen::ir::mir::ty::MirType; use crate::codegen::parser::mir::attribute_parser::FrbAttributes; -use crate::codegen::parser::mir::type_parser::misc::parse_type_should_ignore_simple; use crate::codegen::parser::mir::type_parser::unencodable::SplayedSegment; use crate::library::codegen::ir::mir::ty::MirTypeTrait; +use crate::utils::crate_name::CrateName; use crate::utils::namespace::{Namespace, NamespacedName}; use log::debug; use std::collections::{HashMap, HashSet}; @@ -168,3 +168,17 @@ fn compute_name_and_wrapper_name( }; (namespaced_name, wrapper_name) } + +// TODO rename +pub(crate) fn parse_type_should_ignore_simple( + src_object: &HirStructOrEnum, + crate_name: &CrateName, +) -> bool { + let attrs = FrbAttributes::parse(src_object.src.attrs()).unwrap(); + + attrs.ignore() + // For third party crates, if a struct is not public, then it is impossible to utilize it, + // thus we ignore it. + || (crate_name != &CrateName::self_crate() && src_object.visibility != HirVisibility::Public) + || TODO +} diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs index ef2ce484f4..f26260b3c9 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs @@ -12,11 +12,9 @@ use crate::codegen::ir::mir::ty::MirType; use crate::codegen::ir::mir::ty::MirType::{Delegate, EnumRef}; use crate::codegen::parser::mir::attribute_parser::FrbAttributes; use crate::codegen::parser::mir::type_parser::enum_or_struct::{ - EnumOrStructParser, EnumOrStructParserInfo, -}; -use crate::codegen::parser::mir::type_parser::misc::{ - parse_comments, parse_type_should_ignore_simple, + parse_type_should_ignore_simple, EnumOrStructParser, EnumOrStructParserInfo, }; +use crate::codegen::parser::mir::type_parser::misc::parse_comments; use crate::codegen::parser::mir::type_parser::structure::structure_compute_default_opaque; use crate::codegen::parser::mir::type_parser::unencodable::SplayedSegment; use crate::codegen::parser::mir::type_parser::TypeParserWithContext; diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs index 4d5c89ac24..22ac92a562 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs @@ -50,17 +50,3 @@ fn parse_comment(input: &str) -> MirComment { format!("///{input}") }) } - -// TODO rename -pub(crate) fn parse_type_should_ignore_simple( - src_object: &HirStructOrEnum, - crate_name: &CrateName, -) -> bool { - let attrs = FrbAttributes::parse(src_object.src.attrs()).unwrap(); - - attrs.ignore() - // For third party crates, if a struct is not public, then it is impossible to utilize it, - // thus we ignore it. - || (crate_name != &CrateName::self_crate() && src_object.visibility != HirVisibility::Public) - || TODO -} diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs index fd15f46d8d..6abdd4f576 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs @@ -6,11 +6,9 @@ use crate::codegen::ir::mir::ty::MirType; use crate::codegen::ir::mir::ty::MirType::StructRef; use crate::codegen::parser::mir::attribute_parser::FrbAttributes; use crate::codegen::parser::mir::type_parser::enum_or_struct::{ - EnumOrStructParser, EnumOrStructParserInfo, -}; -use crate::codegen::parser::mir::type_parser::misc::{ - parse_comments, parse_type_should_ignore_simple, + parse_type_should_ignore_simple, EnumOrStructParser, EnumOrStructParserInfo, }; +use crate::codegen::parser::mir::type_parser::misc::parse_comments; use crate::codegen::parser::mir::type_parser::unencodable::SplayedSegment; use crate::codegen::parser::mir::type_parser::TypeParserWithContext; use crate::utils::namespace::{Namespace, NamespacedName}; From 1583483b7396170f33431a93a8e04d2fa0464289 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 10:01:19 +0800 Subject: [PATCH 09/14] refactor: rename --- .../library/codegen/parser/mir/type_parser/enum_or_struct.rs | 5 ++--- .../library/codegen/parser/mir/type_parser/enumeration.rs | 4 ++-- .../src/library/codegen/parser/mir/type_parser/structure.rs | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs index ec816c6193..8643b5a6cc 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs @@ -107,7 +107,7 @@ where self.parse_type_rust_auto_opaque_implicit( Some(namespaced_name.namespace.clone()), &syn::parse_str(&namespaced_name.name)?, - Some(parse_type_should_ignore_simple( + Some(parse_struct_or_enum_should_ignore( src_object, &namespaced_name.namespace.crate_name(), )), @@ -169,8 +169,7 @@ fn compute_name_and_wrapper_name( (namespaced_name, wrapper_name) } -// TODO rename -pub(crate) fn parse_type_should_ignore_simple( +pub(crate) fn parse_struct_or_enum_should_ignore( src_object: &HirStructOrEnum, crate_name: &CrateName, ) -> bool { diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs index f26260b3c9..f1178f9a30 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs @@ -12,7 +12,7 @@ use crate::codegen::ir::mir::ty::MirType; use crate::codegen::ir::mir::ty::MirType::{Delegate, EnumRef}; use crate::codegen::parser::mir::attribute_parser::FrbAttributes; use crate::codegen::parser::mir::type_parser::enum_or_struct::{ - parse_type_should_ignore_simple, EnumOrStructParser, EnumOrStructParserInfo, + parse_struct_or_enum_should_ignore, EnumOrStructParser, EnumOrStructParserInfo, }; use crate::codegen::parser::mir::type_parser::misc::parse_comments; use crate::codegen::parser::mir::type_parser::structure::structure_compute_default_opaque; @@ -49,7 +49,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { let mode = compute_enum_mode(&raw_variants); let variants = maybe_field_wrap_box(raw_variants, mode); - let ignore = parse_type_should_ignore_simple(src_enum, &name.namespace.crate_name()); + let ignore = parse_struct_or_enum_should_ignore(src_enum, &name.namespace.crate_name()); Ok(MirEnum { name, diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs index 6abdd4f576..2572e30145 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs @@ -6,7 +6,7 @@ use crate::codegen::ir::mir::ty::MirType; use crate::codegen::ir::mir::ty::MirType::StructRef; use crate::codegen::parser::mir::attribute_parser::FrbAttributes; use crate::codegen::parser::mir::type_parser::enum_or_struct::{ - parse_type_should_ignore_simple, EnumOrStructParser, EnumOrStructParserInfo, + parse_struct_or_enum_should_ignore, EnumOrStructParser, EnumOrStructParserInfo, }; use crate::codegen::parser::mir::type_parser::misc::parse_comments; use crate::codegen::parser::mir::type_parser::unencodable::SplayedSegment; @@ -51,7 +51,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { let attributes = FrbAttributes::parse(&src_struct.src.attrs)?; let dart_metadata = attributes.dart_metadata(); - let ignore = parse_type_should_ignore_simple(src_struct, &name.namespace.crate_name()); + let ignore = parse_struct_or_enum_should_ignore(src_struct, &name.namespace.crate_name()); Ok(MirStruct { name, From 61a1b0334db1567bb1dcd0a0dc89ed76e6849ce0 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 10:02:10 +0800 Subject: [PATCH 10/14] feat: impl --- .../codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs | 6 ++++++ .../codegen/parser/mir/type_parser/enum_or_struct.rs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs index 105569329e..040ffcddd1 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs @@ -4,6 +4,8 @@ pub(crate) trait SynItemStructOrEnum: Clone { fn attrs(&self) -> &[Attribute]; fn attrs_mut(&mut self) -> &mut Vec; + + fn generics(&self) -> &Generics; } macro_rules! impl_trait { @@ -16,6 +18,10 @@ macro_rules! impl_trait { fn attrs_mut(&mut self) -> &mut Vec { &mut self.attrs } + + fn generics(&self) -> &syn::Generics { + &self.generics + } } }; } diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs index 8643b5a6cc..66ea915a66 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs @@ -179,5 +179,5 @@ pub(crate) fn parse_struct_or_enum_should_ignore( // For third party crates, if a struct is not public, then it is impossible to utilize it, // thus we ignore it. || (crate_name != &CrateName::self_crate() && src_object.visibility != HirVisibility::Public) - || TODO + || !src_object.src.generics().params.is_empty() } From 58c946b2315ebdc12ae5a70d35eaff14a6051cb8 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 10:02:30 +0800 Subject: [PATCH 11/14] chore: lint --- .../library/codegen/parser/mir/type_parser/enum_or_struct.rs | 1 - .../library/codegen/parser/mir/type_parser/enumeration.rs | 2 -- .../src/library/codegen/parser/mir/type_parser/misc.rs | 5 ----- 3 files changed, 8 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs index 66ea915a66..7af40f541c 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs @@ -37,7 +37,6 @@ where if let Some(src_object) = self.src_objects().get(*name) { let src_object = (*src_object).clone(); - let vis = src_object.visibility; let namespace = &src_object.namespaced_name.namespace; let namespaced_name = NamespacedName::new(namespace.clone(), name.to_string()); diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs index f1178f9a30..62105f2601 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs @@ -37,8 +37,6 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { name: NamespacedName, wrapper_name: Option, ) -> anyhow::Result { - let attributes = FrbAttributes::parse(&src_enum.src.attrs)?; - let comments = parse_comments(&src_enum.src.attrs); let raw_variants = src_enum .src diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs index 22ac92a562..127ce35c34 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs @@ -1,9 +1,4 @@ -use crate::codegen::ir::hir::hierarchical::module::HirVisibility; -use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStructOrEnum; -use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStructOrEnum; use crate::codegen::ir::mir::comment::MirComment; -use crate::codegen::parser::mir::attribute_parser::FrbAttributes; -use crate::utils::crate_name::CrateName; use itertools::Itertools; use syn::*; From c097021c267d33ccc9e64509f848d73d79922d88 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 10:07:42 +0800 Subject: [PATCH 12/14] fix: err --- .../src/library/codegen/parser/mir/auto_accessor_parser/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frb_codegen/src/library/codegen/parser/mir/auto_accessor_parser/mod.rs b/frb_codegen/src/library/codegen/parser/mir/auto_accessor_parser/mod.rs index bf4e4618fb..5c94f9a4ce 100644 --- a/frb_codegen/src/library/codegen/parser/mir/auto_accessor_parser/mod.rs +++ b/frb_codegen/src/library/codegen/parser/mir/auto_accessor_parser/mod.rs @@ -63,6 +63,9 @@ fn parse_auto_accessors_of_struct( if !matches!(ty_direct_parse, MirType::RustAutoOpaqueImplicit(_)) { return Ok(vec![]); } + if ty_direct_parse.ignore() { + return Ok(vec![]); + } let ty_struct_ref = TypeParserWithContext::new(type_parser, &context) .parse_type_path_data_struct(&(&struct_name.name, &[]), Some(false)); From ca6510c853bef818c4dfe492b4490acb5edd088f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 10:08:39 +0800 Subject: [PATCH 13/14] fix: compile --- .../src/library/codegen/parser/mir/auto_accessor_parser/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/auto_accessor_parser/mod.rs b/frb_codegen/src/library/codegen/parser/mir/auto_accessor_parser/mod.rs index 5c94f9a4ce..4b203440f4 100644 --- a/frb_codegen/src/library/codegen/parser/mir/auto_accessor_parser/mod.rs +++ b/frb_codegen/src/library/codegen/parser/mir/auto_accessor_parser/mod.rs @@ -12,6 +12,7 @@ use crate::codegen::parser::mir::sanity_checker::auto_accessor_checker; use crate::codegen::parser::mir::type_parser::{ TypeParser, TypeParserParsingContext, TypeParserWithContext, }; +use crate::library::codegen::ir::mir::ty::MirTypeTrait; use crate::utils::namespace::NamespacedName; use field::parse_auto_accessor_of_field; use itertools::Itertools; @@ -63,7 +64,7 @@ fn parse_auto_accessors_of_struct( if !matches!(ty_direct_parse, MirType::RustAutoOpaqueImplicit(_)) { return Ok(vec![]); } - if ty_direct_parse.ignore() { + if ty_direct_parse.should_ignore(type_parser) { return Ok(vec![]); } From 328ac0e3745068afb1c34072c669d58d6009bcf1 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 10:21:47 +0800 Subject: [PATCH 14/14] chore: goldens --- .../library/codegen/parser/mod/generics/expect_mir.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_mir.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_mir.json index 072f87fe47..636b494ef0 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_mir.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_mir.json @@ -3,7 +3,7 @@ "enum_pool": { "crate::api/MyGenericEnum": { "comments": [], - "ignore": false, + "ignore": true, "mode": "Complex", "name": "crate::api/MyGenericEnum", "variants": [ @@ -528,7 +528,7 @@ ], "generate_eq": true, "generate_hash": true, - "ignore": false, + "ignore": true, "is_fields_named": true, "name": "crate::api/MyGenericStruct", "wrapper_name": null