Skip to content
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

Support &dyn Trait #2054

Merged
merged 98 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
0ac8bbb
refactor: rm generate_implementor_enum
fzyzcjy Jun 9, 2024
be7af1e
feat: demo
fzyzcjy Jun 9, 2024
0a25d27
chore: comment
fzyzcjy Jun 9, 2024
5990c29
chore: codegen
fzyzcjy Jun 9, 2024
d01b436
feat: enable ty
fzyzcjy Jun 9, 2024
d3324be
feat: uncomment
fzyzcjy Jun 9, 2024
06b703b
chore: more
fzyzcjy Jun 9, 2024
fd0a9dc
chore: uncomment
fzyzcjy Jun 9, 2024
0e4ac4d
feat: more
fzyzcjy Jun 9, 2024
ae1557b
feat: more
fzyzcjy Jun 9, 2024
f2b8967
feat: more
fzyzcjy Jun 9, 2024
f8aa826
feat: more
fzyzcjy Jun 9, 2024
4c00f50
feat: more
fzyzcjy Jun 9, 2024
ea4a36d
chore: more
fzyzcjy Jun 9, 2024
67db1d5
feat: more
fzyzcjy Jun 9, 2024
9d45747
feat: field
fzyzcjy Jun 9, 2024
6350586
feat: pass around
fzyzcjy Jun 9, 2024
ac37884
fix: err
fzyzcjy Jun 9, 2024
73973bd
feat: more
fzyzcjy Jun 9, 2024
be3b8bb
feat: more
fzyzcjy Jun 9, 2024
77e389e
fet: more
fzyzcjy Jun 9, 2024
c0e0374
feat: more
fzyzcjy Jun 9, 2024
885a7f7
fix: err
fzyzcjy Jun 9, 2024
40ec05c
chore: codegen
fzyzcjy Jun 9, 2024
a379c5c
feat: more
fzyzcjy Jun 9, 2024
b5a2fad
chore: codegen
fzyzcjy Jun 9, 2024
d5759c8
refactor: minor
fzyzcjy Jun 9, 2024
4c08909
feat: more
fzyzcjy Jun 9, 2024
d4a6bf0
refactor: rename
fzyzcjy Jun 9, 2024
5799fd3
chore: codegen
fzyzcjy Jun 9, 2024
4c99d5f
feat: more
fzyzcjy Jun 9, 2024
616f229
chore: codegen
fzyzcjy Jun 9, 2024
7e45b9c
refactor: extract
fzyzcjy Jun 9, 2024
0850be2
refactor: minor
fzyzcjy Jun 9, 2024
1260964
feat: more
fzyzcjy Jun 9, 2024
0c95864
feat: more
fzyzcjy Jun 9, 2024
9ffff1b
chore: comments
fzyzcjy Jun 9, 2024
cd86637
fix: err
fzyzcjy Jun 9, 2024
a9224d6
feat: more
fzyzcjy Jun 9, 2024
7f44047
chore: codegen
fzyzcjy Jun 9, 2024
0115c02
refactor: extract
fzyzcjy Jun 9, 2024
854e9a1
refactor: rename
fzyzcjy Jun 9, 2024
e21bf06
feat: more
fzyzcjy Jun 9, 2024
92f2073
feat: more
fzyzcjy Jun 9, 2024
9907d15
feat: more
fzyzcjy Jun 9, 2024
acfe2df
fix: err
fzyzcjy Jun 9, 2024
add99f2
refactor: rm
fzyzcjy Jun 9, 2024
eb3dff8
chore: more
fzyzcjy Jun 9, 2024
b96b06f
refactor: rename
fzyzcjy Jun 9, 2024
4bb9303
chore: more
fzyzcjy Jun 9, 2024
e378c24
feat: more
fzyzcjy Jun 9, 2024
2498119
feat: more
fzyzcjy Jun 9, 2024
237279a
feat: more pass around
fzyzcjy Jun 9, 2024
4c8c4b0
feat: more
fzyzcjy Jun 9, 2024
b5ad14b
feat: more
fzyzcjy Jun 9, 2024
539c070
feat: more
fzyzcjy Jun 9, 2024
22a2794
feat: more
fzyzcjy Jun 9, 2024
803129e
feat: more
fzyzcjy Jun 9, 2024
0fbab06
feat: more
fzyzcjy Jun 9, 2024
0d18e33
feat: more
fzyzcjy Jun 9, 2024
8ab2b78
feat: more
fzyzcjy Jun 9, 2024
76b713a
feat: more
fzyzcjy Jun 9, 2024
9c0b46d
fix: err
fzyzcjy Jun 9, 2024
259a2d2
chore: codegen
fzyzcjy Jun 9, 2024
bc300b5
feat: more
fzyzcjy Jun 9, 2024
a1bc41a
feat: more
fzyzcjy Jun 9, 2024
507b35f
feat: more
fzyzcjy Jun 9, 2024
ec4c3bf
fix: err
fzyzcjy Jun 9, 2024
98dd595
chore: codegen
fzyzcjy Jun 9, 2024
b6150c7
feat: test
fzyzcjy Jun 9, 2024
775b858
feat: more
fzyzcjy Jun 9, 2024
4ce8222
chore: codegen
fzyzcjy Jun 9, 2024
134680a
chore: rm
fzyzcjy Jun 9, 2024
b200b4e
feat: mv test
fzyzcjy Jun 9, 2024
73d35b1
Merge branch 'master' into feat/12190
fzyzcjy Jun 9, 2024
cb1f4e5
chore: codegen
fzyzcjy Jun 9, 2024
4df0121
Merge remote-tracking branch 'origin/feat/12190' into feat/12190
fzyzcjy Jun 9, 2024
35c033b
chore: rm
fzyzcjy Jun 9, 2024
e64020c
chore: codegen
fzyzcjy Jun 9, 2024
ae6bfea
feat: more
fzyzcjy Jun 9, 2024
6f4d75d
feat: more
fzyzcjy Jun 9, 2024
557d6d6
chore: codegen
fzyzcjy Jun 9, 2024
62aeaab
feat: more
fzyzcjy Jun 9, 2024
1191328
chore: rm
fzyzcjy Jun 9, 2024
e4ab13f
feat: more
fzyzcjy Jun 9, 2024
83e0ae6
chore: lint
fzyzcjy Jun 9, 2024
e5115de
chore: more
fzyzcjy Jun 9, 2024
1c28e3b
chore: lint
fzyzcjy Jun 9, 2024
f686d29
feat: more
fzyzcjy Jun 9, 2024
e00ebca
chore: codegen
fzyzcjy Jun 9, 2024
725a94c
chore: lint
fzyzcjy Jun 9, 2024
cd53b37
chore: lint
fzyzcjy Jun 9, 2024
e8fe5a0
chore: goldens
fzyzcjy Jun 9, 2024
1b47513
fix: err
fzyzcjy Jun 9, 2024
40bc70c
chore: more
fzyzcjy Jun 9, 2024
f76c126
chore: more
fzyzcjy Jun 9, 2024
044203b
chore: more
fzyzcjy Jun 9, 2024
c0d450b
chore: lint
fzyzcjy Jun 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use super::*;
use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
use flutter_rust_bridge::for_generated::transform_result_dco;
use flutter_rust_bridge::for_generated::{transform_result_dco, Lockable};
use flutter_rust_bridge::{Handler, IntoIntoDart};

// Section: boilerplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// Section: imports

use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
use flutter_rust_bridge::for_generated::transform_result_dco;
use flutter_rust_bridge::for_generated::{transform_result_dco, Lockable};
use flutter_rust_bridge::{Handler, IntoIntoDart};

// Section: boilerplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

use super::*;
use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
use flutter_rust_bridge::for_generated::transform_result_dco;
use flutter_rust_bridge::for_generated::wasm_bindgen;
use flutter_rust_bridge::for_generated::wasm_bindgen::prelude::*;
use flutter_rust_bridge::for_generated::{transform_result_dco, Lockable};
use flutter_rust_bridge::{Handler, IntoIntoDart};

// Section: boilerplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import 'api/simple.dart';
import 'dart:async';
import 'dart:convert';
import 'frb_generated.dart';
import 'frb_generated.io.dart' if (dart.library.html) 'frb_generated.web.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn compute_class_name_for_querying_methods(ty: &MirType) -> NamespacedName {
MirType::StructRef(ty) => ty.ident.0.clone(),
MirType::TraitDef(ty) => ty.name.clone(),
MirType::Delegate(MirTypeDelegate::ProxyVariant(ty)) => {
compute_class_name_for_querying_methods(&*ty.inner)
compute_class_name_for_querying_methods(&ty.inner)
}
MirType::RustAutoOpaqueImplicit(ty) => {
compute_class_name_for_querying_methods(&MirType::RustOpaque(ty.inner.clone()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::codegen::ir::mir::ty::MirType;
use crate::library::codegen::generator::api_dart::spec_generator::base::*;
use crate::library::codegen::generator::api_dart::spec_generator::info::ApiDartGeneratorInfoTrait;
use crate::utils::basic_code::dart_header_code::DartHeaderCode;
use crate::utils::namespace::NamespacedName;

impl<'a> ApiDartGeneratorClassTrait for DelegateApiDartGenerator<'a> {
fn generate_class(&self) -> Option<ApiDartGeneratedClass> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ use crate::library::codegen::generator::api_dart::spec_generator::base::*;
use crate::library::codegen::generator::api_dart::spec_generator::info::ApiDartGeneratorInfoTrait;
use crate::library::codegen::ir::mir::ty::MirTypeTrait;
use crate::utils::basic_code::dart_header_code::DartHeaderCode;
use crate::utils::namespace::NamespacedName;
use itertools::{concat, Itertools};
use lazy_static::lazy_static;
use regex::Regex;

impl<'a> ApiDartGeneratorClassTrait for RustOpaqueApiDartGenerator<'a> {
fn generate_class(&self) -> Option<ApiDartGeneratedClass> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ impl<'a> ApiDartGeneratorInfoTrait for DelegateApiDartGenerator<'a> {
MirTypeDelegate::BigPrimitive(_) => "BigInt".to_owned(),
MirTypeDelegate::RustAutoOpaqueExplicit(mir) => {
ApiDartGenerator::new(mir.inner.clone(), self.context).dart_api_type()
} // MirTypeDelegate::DynTrait(mir) => mir.trait_def_name.name.clone(),
}
MirTypeDelegate::ProxyVariant(mir) => {
ApiDartGenerator::new(mir.inner.clone(), self.context).dart_api_type()
}
MirTypeDelegate::ProxyEnum(mir) => {
ApiDartGenerator::new(mir.original.clone(), self.context).dart_api_type()
}
MirTypeDelegate::DynTrait(mir) => mir.trait_def_name.name.clone(),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,13 @@ fn generate_imports_from_ty(
current_file_namespace,
);
let path_b = (path_b_inner.parent()).with_context(|| {
// This will stop the whole generator and tell the users, so we do not care about testing it
// frb-coverage:ignore-start
format!(
"no parent for path_b_inner={path_b_inner:?} \
(current_file_namespace={current_file_namespace}, ty_namespace={ty_namespace} current_file_namespace={current_file_namespace:?} ty={ty:?})"
)
// frb-coverage:ignore-end
});

let path_diff = diff_paths(path_a, path_b?).context("cannot diff path")?;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use itertools::Itertools;

pub(super) fn generate_encode_to_enum(enum_name: &str, variants: &[VariantInfo]) -> String {
let variants = (variants.iter())
.map(|variant| {
format!(
"if (self is {ty_name}) {{
return {enum_name}.{enum_variant_name}(self{extra_code});
}}
",
ty_name = variant.ty_name,
enum_variant_name = variant.enum_variant_name,
extra_code = variant.extra_code,
)
})
.join("");

format!(
"
(() {{
{variants}
throw Exception('not reachable');
}})()
"
)
}

pub(crate) struct VariantInfo {
pub enum_variant_name: String,
pub ty_name: String,
pub extra_code: String,
}
1 change: 1 addition & 0 deletions frb_codegen/src/library/codegen/generator/codec/sse/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod encode_to_enum;
pub(crate) mod lang;
pub(crate) mod misc;
pub(crate) mod ty;
69 changes: 40 additions & 29 deletions frb_codegen/src/library/codegen/generator/codec/sse/ty/delegate.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::codegen::generator::api_dart::spec_generator::base::ApiDartGenerator;
use crate::codegen::generator::api_dart::spec_generator::class::proxy_variant;
use crate::codegen::generator::codec::sse::encode_to_enum;
use crate::codegen::generator::codec::sse::lang::*;
use crate::codegen::generator::codec::sse::ty::*;
use crate::codegen::ir::mir::ty::delegate::{
MirTypeDelegatePrimitiveEnum, MirTypeDelegateProxyEnum, MirTypeDelegateSet,
MirTypeDelegateStreamSink, MirTypeDelegateTime,
MirTypeDelegateDynTrait, MirTypeDelegatePrimitiveEnum, MirTypeDelegateProxyEnum,
MirTypeDelegateSet, MirTypeDelegateStreamSink, MirTypeDelegateTime,
};
use crate::library::codegen::generator::api_dart::spec_generator::info::ApiDartGeneratorInfoTrait;
use convert_case::{Case, Casing};
Expand Down Expand Up @@ -46,7 +47,10 @@ impl<'a> CodecSseTyTrait for DelegateCodecSseTy<'a> {
MirTypeDelegate::RustAutoOpaqueExplicit(_ir) => "self".to_owned(),
MirTypeDelegate::ProxyEnum(mir) => {
generate_proxy_enum_dart_encode(mir, self.context.as_api_dart_context())
} // MirTypeDelegate::DynTrait(_ir) => lang.throw_unimplemented(""),
}
MirTypeDelegate::DynTrait(mir) => {
generate_dyn_trait_dart_encode(mir, self.context.as_api_dart_context())
}
},
Lang::RustLang(_) => match &self.mir {
MirTypeDelegate::Array(_) => {
Expand Down Expand Up @@ -85,18 +89,15 @@ impl<'a> CodecSseTyTrait for DelegateCodecSseTy<'a> {
}
},
MirTypeDelegate::Uuid => "self.as_bytes().to_vec()".to_owned(),
MirTypeDelegate::StreamSink(_)
/*| MirTypeDelegate::DynTrait(_)*/ => {
return Some(lang.throw_unimplemented(""))
}
MirTypeDelegate::StreamSink(_) => return Some(lang.throw_unimplemented("")),
MirTypeDelegate::BigPrimitive(_) => "self.to_string()".to_owned(),
MirTypeDelegate::RustAutoOpaqueExplicit(_ir) => {
"flutter_rust_bridge::for_generated::rust_auto_opaque_explicit_encode(self)"
.to_owned()
}
MirTypeDelegate::ProxyVariant(_)
| MirTypeDelegate::ProxyEnum(_)
=> return None,
| MirTypeDelegate::DynTrait(_) => return None,
},
};
Some(simple_delegate_encode(
Expand Down Expand Up @@ -155,7 +156,9 @@ impl<'a> CodecSseTyTrait for DelegateCodecSseTy<'a> {
}
MirTypeDelegate::BigPrimitive(_) => "BigInt.parse(inner)".to_owned(),
MirTypeDelegate::RustAutoOpaqueExplicit(_ir) => "inner".to_owned(),
// MirTypeDelegate::DynTrait(_) => return Some(lang.throw_unimplemented("")),
MirTypeDelegate::DynTrait(_) => {
return Some(format!("{};", lang.throw_unimplemented("")))
}
}
}
Lang::RustLang(_) => match &self.mir {
Expand Down Expand Up @@ -197,8 +200,10 @@ impl<'a> CodecSseTyTrait for DelegateCodecSseTy<'a> {
MirTypeDelegate::RustAutoOpaqueExplicit(_ir) => {
"flutter_rust_bridge::for_generated::rust_auto_opaque_explicit_decode(inner)"
.to_owned()
} // MirTypeDelegate::DynTrait(_ir) => lang.throw_unimplemented(""),
MirTypeDelegate::ProxyVariant(_) | MirTypeDelegate::ProxyEnum(_) => return None,
}
MirTypeDelegate::ProxyVariant(_)
| MirTypeDelegate::ProxyEnum(_)
| MirTypeDelegate::DynTrait(_) => return None,
},
};

Expand Down Expand Up @@ -289,26 +294,32 @@ fn generate_proxy_enum_dart_encode(
mir: &MirTypeDelegateProxyEnum,
context: ApiDartGeneratorContext,
) -> String {
let enum_name = mir.proxy_enum_name();
let enum_name = mir.delegate_enum_name();

let variants = (mir.variants.iter().enumerate())
.map(|(index, variant)| {
let variant_dart_extra_type = proxy_variant::compute_dart_extra_type(variant, context);
format!(
"if (self is {variant_dart_extra_type}) {{
return {enum_name}.variant{index}(self._upstream);
}}
"
)
.map(|(index, variant)| encode_to_enum::VariantInfo {
enum_variant_name: format!("variant{index}"),
ty_name: proxy_variant::compute_dart_extra_type(variant, context),
extra_code: "._upstream".to_owned(),
})
.join("");
.collect_vec();

format!(
"
(() {{
{variants}
throw Exception('not reachable');
}})()
"
)
encode_to_enum::generate_encode_to_enum(&enum_name, &variants)
}

fn generate_dyn_trait_dart_encode(
mir: &MirTypeDelegateDynTrait,
context: ApiDartGeneratorContext,
) -> String {
let enum_name = mir.delegate_enum_name();

let variants = (mir.data().variants.iter().enumerate())
.map(|(index, variant)| encode_to_enum::VariantInfo {
enum_variant_name: format!("variant{index}"),
ty_name: ApiDartGenerator::new(variant.ty.clone(), context).dart_api_type(),
extra_code: "".to_owned(),
})
.collect_vec();

encode_to_enum::generate_encode_to_enum(&enum_name, &variants)
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<'a> WireDartCodecCstGeneratorEncoderTrait for DelegateWireDartCodecCstGener
// ))),
MirTypeDelegate::Backtrace
| MirTypeDelegate::AnyhowException
/*| MirTypeDelegate::DynTrait(_)*/ => {
| MirTypeDelegate::DynTrait(_) => {
Acc::distribute(Some("throw UnimplementedError();".to_string()))
}
MirTypeDelegate::Map(_) => Acc::distribute(Some(format!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<'a> WireDartCodecDcoGeneratorDecoderTrait for DelegateWireDartCodecDcoGener
"return Set.from(dco_decode_{}(raw));",
self.mir.get_delegate().safe_ident(),
),
MirTypeDelegate::StreamSink(_) /*| MirTypeDelegate::DynTrait(_)*/ => "throw UnimplementedError();".to_owned(),
MirTypeDelegate::StreamSink(_) | MirTypeDelegate::DynTrait(_) => "throw UnimplementedError();".to_owned(),
MirTypeDelegate::BigPrimitive(_) => {
"return BigInt.parse(raw);".to_owned()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<'a> WireRustCodecCstGeneratorDecoderTrait for DelegateWireRustCodecCstGener
// "let multiple: Vec<u8> = self.cst_decode(); flutter_rust_bridge::for_generated::decode_uuids(multiple)".into(),
// ),
// ),
MirTypeDelegate::Backtrace | MirTypeDelegate::AnyhowException /*| MirTypeDelegate::DynTrait(_)*/ => Acc::new(|target| match target {
MirTypeDelegate::Backtrace | MirTypeDelegate::AnyhowException | MirTypeDelegate::DynTrait(_) => Acc::new(|target| match target {
TargetOrCommon::Common => None,
TargetOrCommon::Io | TargetOrCommon::Web => Some("unimplemented!()".into()),
}),
Expand Down Expand Up @@ -134,7 +134,7 @@ impl<'a> WireRustCodecCstGeneratorDecoderTrait for DelegateWireRustCodecCstGener
"self.unchecked_into::<flutter_rust_bridge::for_generated::js_sys::Uint8Array>().to_vec().into_boxed_slice().cst_decode()"
.into()
}
MirTypeDelegate::Backtrace | MirTypeDelegate::AnyhowException /*| MirTypeDelegate::DynTrait(_)*/ => "unimplemented!()".into(),
MirTypeDelegate::Backtrace | MirTypeDelegate::AnyhowException | MirTypeDelegate::DynTrait(_) => "unimplemented!()".into(),
MirTypeDelegate::Array(array) => generate_decode_array(array)
.into(),
MirTypeDelegate::Map(mir) => generate_decode_map(mir).into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
Some(ty.ownership_mode)
}
MirType::Delegate(MirTypeDelegate::ProxyEnum(ty)) => compute_interest_field(&ty.original),
// temporarily only support Ref
MirType::Delegate(MirTypeDelegate::DynTrait(_)) => Some(OwnershipMode::Ref),
_ => None,
}
}
Expand All @@ -107,3 +109,14 @@
field: &'a MirFuncInput,
ownership_mode: OwnershipMode,
}

pub(crate) fn generate_inner_func_arg_ownership(field: &MirFuncInput) -> String {

Check warning on line 113 in frb_codegen/src/library/codegen/generator/wire/rust/spec_generator/misc/function/lockable.rs

View check run for this annotation

Codecov / codecov/patch

frb_codegen/src/library/codegen/generator/wire/rust/spec_generator/misc/function/lockable.rs#L113

Added line #L113 was not covered by tests
match &field.inner.ty {
MirType::RustAutoOpaqueImplicit(_) | MirType::Delegate(MirTypeDelegate::DynTrait(_)) => {
"".to_owned()
}
_ => (field.ownership_mode.map(|x| x.prefix()))
.unwrap_or_default()
.to_owned(),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::codegen::generator::wire::rust::spec_generator::output_code::WireRust
use crate::codegen::ir::mir::func::{MirFunc, MirFuncMode, MirFuncOwnerInfo};
use crate::codegen::ir::mir::ty::primitive::MirTypePrimitive;
use crate::codegen::ir::mir::ty::MirType;
use crate::if_then_some;
use crate::misc::consts::HANDLER_NAME;
use convert_case::{Case, Casing};
use itertools::Itertools;
Expand Down Expand Up @@ -70,22 +69,12 @@ pub(crate) fn generate_wire_func(
}

fn generate_inner_func_args(func: &MirFunc) -> Vec<String> {
let ans = func
.inputs
.iter()
(func.inputs.iter())
.map(|field| {
let mut ans = format!("api_{}", field.inner.name.rust_style());
let ownership_mode =
if_then_some!(let MirType::RustAutoOpaqueImplicit(o) = &field.inner.ty, o.ownership_mode)
.or(field.ownership_mode);
if let Some(ownership_mode) = ownership_mode {
ans = format!("{}{ans}", ownership_mode.prefix())
}
ans
let ownership = lockable::generate_inner_func_arg_ownership(field);
format!("{ownership}api_{}", field.inner.name.rust_style())
})
.collect_vec();

ans
.collect_vec()
}

fn generate_wrap_info_obj(func: &MirFunc) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ impl<'a> WireRustGeneratorMiscTrait for DelegateWireRustGenerator<'a> {
}

fn generate_wire_func_call_decode_type(&self) -> Option<String> {
if let MirTypeDelegate::ProxyEnum(mir) = &self.mir {
Some(mir.get_delegate().rust_api_type())
} else {
None
match &self.mir {
MirTypeDelegate::ProxyEnum(mir) => Some(mir.get_delegate().rust_api_type()),
MirTypeDelegate::DynTrait(mir) => Some(mir.get_delegate().rust_api_type()),
_ => None,
}
}
}
1 change: 1 addition & 0 deletions frb_codegen/src/library/codegen/ir/early_generator/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub(crate) mod pack;
pub(crate) mod proxied_type;
pub(crate) mod trait_def_info;
3 changes: 2 additions & 1 deletion frb_codegen/src/library/codegen/ir/early_generator/pack.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::codegen::ir::early_generator::proxied_type::IrEarlyGeneratorProxiedType;
use crate::codegen::ir::early_generator::trait_def_info::IrEarlyGeneratorTraitDefInfo;
use crate::codegen::ir::hir::flat::pack::HirFlatPack;
use crate::codegen::ir::mir::ty::MirType;

#[derive(Debug, Clone, Default, serde::Serialize)]
pub(crate) struct IrEarlyGeneratorPack {
pub hir_flat_pack: HirFlatPack,
pub proxied_types: Vec<IrEarlyGeneratorProxiedType>,
pub trait_def_infos: Vec<IrEarlyGeneratorTraitDefInfo>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::utils::namespace::Namespace;

#[derive(Debug, Clone, serde::Serialize, PartialEq, Eq, Hash)]
pub(crate) struct IrEarlyGeneratorProxiedType {
pub proxy_enum_namespace: Namespace,
pub original_ty: MirType,
pub proxy_enum_namespace: Namespace,
pub variants: Vec<MirTypeDelegateProxyVariant>,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::codegen::ir::mir::ty::delegate::MirTypeDelegateDynTraitVariant;
use crate::utils::namespace::{Namespace, NamespacedName};

#[derive(Debug, Clone, serde::Serialize, PartialEq, Eq, Hash)]
pub(crate) struct IrEarlyGeneratorTraitDefInfo {
pub trait_def_name: NamespacedName,
pub delegate_namespace: Namespace,
pub variants: Vec<MirTypeDelegateDynTraitVariant>,
}
Loading
Loading