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

Geneartion of async functions when default_dart_async: false #2178

Closed
Larpoux opened this issue Jul 2, 2024 · 13 comments · Fixed by #2190
Closed

Geneartion of async functions when default_dart_async: false #2178

Larpoux opened this issue Jul 2, 2024 · 13 comments · Fixed by #2190
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc bug Something isn't working

Comments

@Larpoux
Copy link
Contributor

Larpoux commented Jul 2, 2024

Describe the bug

When I set the parameter default_dart_async: false I get after, 10 errors.
Most of them are in class Context and ContextOffline.

For example :

fn wire__web_audio_api__context__OfflineAudioContext_suspend_impl(
    ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
    rust_vec_len_: i32,
    data_len_: i32,
) -> flutter_rust_bridge::for_generated::WireSyncRust2DartSse {
    FLUTTER_RUST_BRIDGE_HANDLER.wrap_sync::<flutter_rust_bridge::for_generated::SseCodec, _>(
        flutter_rust_bridge::for_generated::TaskInfo {
            debug_name: "OfflineAudioContext_suspend",
            port: None,
            mode: flutter_rust_bridge::for_generated::FfiCallMode::Sync,
        },
        move || {
            let message = unsafe {
                flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(
                    ptr_,
                    rust_vec_len_,
                    data_len_,
                )
            };
            let mut deserializer =
                flutter_rust_bridge::for_generated::SseDeserializer::new(message);
            let api_that = <RustOpaqueMoi<
                flutter_rust_bridge::for_generated::RustAutoOpaqueInner<OfflineAudioContext>,
            >>::sse_decode(&mut deserializer);
            let api_suspend_time = <f64>::sse_decode(&mut deserializer);
            deserializer.end();
            transform_result_sse::<_, ()>((move || {
                let mut api_that_guard = None;
                let decode_indices_ =
                    flutter_rust_bridge::for_generated::lockable_compute_decode_order(vec![
                        flutter_rust_bridge::for_generated::LockableOrderInfo::new(
                            &api_that, 0, false,
                        ),
                    ]);
                for i in decode_indices_ {
                    match i {
                        0 => api_that_guard = Some(api_that.lockable_decode_async_ref().await),
                        _ => unreachable!(),
                    }
                }
                let api_that_guard = api_that_guard.unwrap();
                let output_ok = Result::<_, ()>::Ok({
                    web_audio_api::context::OfflineAudioContext::suspend(
                        &*api_that_guard,
                        api_suspend_time,
                    )
                    .await;
                })?;
                Ok(output_ok)
            })())
        },
    )
}

The await almost at the end of the fn is NOK, because the function is not async.
I think the problem is tied with the declaration of suspend() in the WebAudioApi-RS :

    pub async fn suspend(&self, suspend_time: f64) {

Probably that our generated fn should be async too

fn wire__web_audio_api__context__OfflineAudioContext_suspend_impl(

Steps to reproduce

Logs

-

Expected behavior

No response

Generated binding code

No response

OS

No response

Version of flutter_rust_bridge_codegen

No response

Flutter info

No response

Version of clang++

No response

Additional context

No response

@Larpoux Larpoux added the bug Something isn't working label Jul 2, 2024
@fzyzcjy
Copy link
Owner

fzyzcjy commented Jul 2, 2024

Totally agree! We should detect when seeing async fn and mark it as async no matter how users choose default_dart_async=false.

Feel free to PR, or alternatively I will work on it in the next batch!

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Jul 2, 2024
@Larpoux
Copy link
Contributor Author

Larpoux commented Jul 3, 2024

I am going to look to the frb code. Don’t do anything on this issue until I declare that it is too complicated for me and that I need your help.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jul 3, 2024

Sure! If you need any hints (e.g. where to look at / how to fix) just ping me.

@Larpoux
Copy link
Contributor Author

Larpoux commented Jul 3, 2024

Please, how can I start FRB under debugger ? Can I use Rust Rover for example ? Which project must I open ? Do I have to setup a specific configuration to run the debugger ?

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jul 3, 2024

frb code generator (frb_codegen folder) is nothing but a standard Rust program. Thus yes, you can use arbitrary IDE you like (e.g. rustrover) and follow their guides to start debuggers.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jul 3, 2024

You may need to add several command line flags: generate --config-file /path/to/your/flutter_rust_bridge/frb_example/integrate_third_party/flutter_rust_bridge.yaml (IIRC that may work)

@Larpoux
Copy link
Contributor Author

Larpoux commented Jul 3, 2024

I am going to look to the frb code. Don’t do anything on this issue until I declare that it is too complicated for me and that I need your help.

Sure! If you need any hints (e.g. where to look at / how to fix) just ping me.

I did something to fix this issue, but I had many problems because we diverged.
I finally was able to get rid of your modification, but now I realize that your modification is better than mine because I don’t handle correctly the case of a function which is not async, the default value is async, but the user specified #[frb(sync)].
I am going to restore your own patch tomorrow, but please, let me alone on this issue. Or tell me explicitly that I must not work any more on this issue.

@Larpoux
Copy link
Contributor Author

Larpoux commented Jul 3, 2024

I am going to restore your own patch tomorrow, but please, let me alone on this issue. Or tell me explicitly that I must not work any more on this issue.

This is stupid. Better for me to cancel my PR.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jul 4, 2024

I guess you meant #2181? No it is unrelated to this issue!

Firstly it was started (i.e. the first code commit time) before you mentioned wanting to work on this issue. Secondly it was done to fix the scenario that someone chooses default_dart_async: false and then want to make a fn (note: this isssue is about async fn) async on Dart side. Thus it is parallal to this issue.

In other words, there are 3 scenarios when default_dart_async:false:

  • fn - it is dart sync
  • #[frb(dart_async)] fn - it should be dart async (after my PR yesterday)
  • async fn - it should be dart async (waiting for your PR)

@Larpoux
Copy link
Contributor Author

Larpoux commented Jul 4, 2024

No problem, @fzyzcjy . I was very glad to have a preview of the frb code.
I am going to check if [#2178] is solved by your commit.
If not, I will reopen the issue and will redo a fix. Certainly today.

‘Thanks for your tremendous work. 👍 .
Btw : Is it you the guy who created this amazing project ?
I am really impressed by how sophisticated this project is. I hope to have some opportunities to work on it, because I can learn much things by working with the FRB team.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jul 4, 2024

I am going to check if [...] is solved by your commit.

I guess not solved since I do not touch anything related to async fn signature parsing.

Btw : Is it you the guy who created this amazing project ?

Yes - you can have a look at the commit history. But not only me - there are many people who contribute to this project (view https://github.com/fzyzcjy/flutter_rust_bridge#-acknowledgments-and-contributors for a full list and details). Many of them contribute something small like fixing a typo, but there are some people who contribute a lot to the project, making it grow from a tiny project into a much bigger one. On the other hand, v2's overhaul and new features are mostly done by me (again check the list/commit history for details).

@Larpoux
Copy link
Contributor Author

Larpoux commented Jul 4, 2024

Fixed by PR [#2187]. (I hope)

Copy link
Contributor

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc bug Something isn't working
Projects
None yet
2 participants