From 99f5beee9aedcd264c931973457e1c1a3db5a86d Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 10:59:50 +0800 Subject: [PATCH 1/5] chore: empty --- .../codegen/parser/mir/function_parser/output.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs index 056dcb3250..fa17f96e65 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs @@ -1,4 +1,5 @@ use crate::codegen::ir::mir::ty::primitive::MirTypePrimitive; +use crate::codegen::ir::mir::ty::rust_auto_opaque_implicit::MirTypeRustAutoOpaqueImplicit; use crate::codegen::ir::mir::ty::MirType; use crate::codegen::parser::mir::function_parser::{FunctionParser, FunctionPartialInfo}; use crate::codegen::parser::mir::type_parser::result::parse_type_maybe_result; @@ -12,9 +13,9 @@ impl<'a, 'b> FunctionParser<'a, 'b> { context: &TypeParserParsingContext, ) -> anyhow::Result { Ok(match &sig.output { - ReturnType::Type(_, ty) => { - remove_primitive_unit(self.parse_fn_output_type(ty, context)?) - } + ReturnType::Type(_, ty) => remove_reference_type(remove_primitive_unit( + self.parse_fn_output_type(ty, context)?, + )), ReturnType::Default => Default::default(), }) } @@ -45,3 +46,7 @@ fn remove_primitive_unit(info: FunctionPartialInfo) -> FunctionPartialInfo { FunctionPartialInfo { ok_output, ..info } } + +fn remove_reference_type(info: FunctionPartialInfo) -> FunctionPartialInfo { + TODO +} From de3e575c1d6643d2d2e669543c458afb29ee1006 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 11:00:09 +0800 Subject: [PATCH 2/5] refactor: simp --- .../codegen/parser/mir/function_parser/output.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs index fa17f96e65..e96caccfaf 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs @@ -38,13 +38,14 @@ impl<'a, 'b> FunctionParser<'a, 'b> { // Convert primitive Unit type -> None fn remove_primitive_unit(info: FunctionPartialInfo) -> FunctionPartialInfo { - let ok_output = if info.ok_output == Some(MirType::Primitive(MirTypePrimitive::Unit)) { - None + if info.ok_output == Some(MirType::Primitive(MirTypePrimitive::Unit)) { + FunctionPartialInfo { + ok_output: None, + ..info + } } else { - info.ok_output - }; - - FunctionPartialInfo { ok_output, ..info } + info + } } fn remove_reference_type(info: FunctionPartialInfo) -> FunctionPartialInfo { From 6a6a65b04eca7ec13d75d07cad079fd37f18ff60 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 11:01:03 +0800 Subject: [PATCH 3/5] feat: more --- .../parser/mir/function_parser/output.rs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs index e96caccfaf..d7098ed4f9 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs @@ -1,3 +1,4 @@ +use crate::codegen::ir::mir::func::OwnershipMode; use crate::codegen::ir::mir::ty::primitive::MirTypePrimitive; use crate::codegen::ir::mir::ty::rust_auto_opaque_implicit::MirTypeRustAutoOpaqueImplicit; use crate::codegen::ir::mir::ty::MirType; @@ -39,15 +40,25 @@ impl<'a, 'b> FunctionParser<'a, 'b> { // Convert primitive Unit type -> None fn remove_primitive_unit(info: FunctionPartialInfo) -> FunctionPartialInfo { if info.ok_output == Some(MirType::Primitive(MirTypePrimitive::Unit)) { - FunctionPartialInfo { + return FunctionPartialInfo { ok_output: None, ..info - } - } else { - info + }; } + info } fn remove_reference_type(info: FunctionPartialInfo) -> FunctionPartialInfo { - TODO + if let MirType::RustAutoOpaqueImplicit(MirTypeRustAutoOpaqueImplicit { + ownership_mode, .. + }) = &info.ok_output + { + if ownership_mode != OwnershipMode::Owned { + return FunctionPartialInfo { + ok_output: None, + ..info + }; + } + } + info } From 9e252ce2f090cf5cb3f0e0e8166ce90e4844d026 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 11:01:25 +0800 Subject: [PATCH 4/5] fix: err --- .../library/codegen/parser/mir/function_parser/output.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs index d7098ed4f9..e53fcd1ff7 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs @@ -49,11 +49,12 @@ fn remove_primitive_unit(info: FunctionPartialInfo) -> FunctionPartialInfo { } fn remove_reference_type(info: FunctionPartialInfo) -> FunctionPartialInfo { - if let MirType::RustAutoOpaqueImplicit(MirTypeRustAutoOpaqueImplicit { - ownership_mode, .. - }) = &info.ok_output + if let Some(MirType::RustAutoOpaqueImplicit(MirTypeRustAutoOpaqueImplicit { + ownership_mode, + .. + })) = &info.ok_output { - if ownership_mode != OwnershipMode::Owned { + if *ownership_mode != OwnershipMode::Owned { return FunctionPartialInfo { ok_output: None, ..info From f02b8df8deabb8f88e6d69460b19a9b3a583cfd6 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 3 Jun 2024 11:02:35 +0800 Subject: [PATCH 5/5] chore: log --- .../src/library/codegen/parser/mir/function_parser/output.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs index e53fcd1ff7..c67b7ad031 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/output.rs @@ -55,6 +55,7 @@ fn remove_reference_type(info: FunctionPartialInfo) -> FunctionPartialInfo { })) = &info.ok_output { if *ownership_mode != OwnershipMode::Owned { + log::debug!("remove_reference_type: detect output type is a reference, thus set to unit (info={:?})", info); return FunctionPartialInfo { ok_output: None, ..info