flutter_rust_bridge icon indicating copy to clipboard operation
flutter_rust_bridge copied to clipboard

[experimental-feature] Error when running third-party scanner

Open pattobrien opened this issue 7 months ago • 14 comments

Describe the bug

I'm not able to run the third party scanner on package yrs, due to the below error.

Further in the debug logs, I see the message "struct with unit fields are not supported yet, what about using struct DefaultProtocol {} or #[frb(opaque)] struct DefaultProtocol; instead" - but the struct in question cannot be modified, since it's a part of third party code.

[2024-07-12T09:20:51.188Z ERROR /Users/pattobrien/.asdf/installs/rust/1.79.0/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.1.0/src/library/utils/logs.rs:55] panicked at /Users/pattobrien/.asdf/installs/rust/1.79.0/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.1.0/src/library/codegen/ir/mir/ty/structure.rs:36:32:
no entry found for key=MirStructIdent(NamespacedName { namespace: Namespace { joined_path: "yrs::sync::protocol" }, name: "DefaultProtocol" })
thread 'main' panicked at /Users/pattobrien/.asdf/installs/rust/1.79.0/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.1.0/src/library/codegen/ir/mir/ty/structure.rs:36:32:
no entry found for key=MirStructIdent(NamespacedName { namespace: Namespace { joined_path: "yrs::sync::protocol" }, name: "DefaultProtocol" })

Steps to reproduce

  1. clone the https://github.com/fzyzcjy/flutter_rust_bridge/tree/master/frb_example/dart_minimal example package.
  2. add yrs as a dependency.
  3. modify flutter_rust_bridge.yaml with rust_input: crate::api,yrs.
  4. run the generator via flutter_rust_bridge_codegen generate

Logs

[2024-07-12T09:22:47.475Z INFO /Users/pattobrien/.asdf/installs/rust/1.79.0/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.1.0/src/library/codegen/parser/hir/flat/transformer/merge_duplicate_transformer/mod.rs:72] There are still multiple objects with same key after merging, thus randomly pick one. This is an issue only if the object is indeed used. (key="Values", objects={"name":"yrs::types::map/Values","visibility":"Public","sources":["Normal"],"mirror":true}, {"name":"yrs::iter/Values","visibility":"Restricted","sources":["Normal"],"mirror":true})
[2024-07-12T09:22:47.475Z INFO /Users/pattobrien/.asdf/installs/rust/1.79.0/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.1.0/src/library/codegen/parser/hir/flat/transformer/merge_duplicate_transformer/mod.rs:72] There are still multiple objects with same key after merging, thus randomly pick one. This is an issue only if the object is indeed used. (key="Doc", objects={"name":"crate::api::yrs/Doc","visibility":"Public","sources":["Normal"],"mirror":true}, {"name":"yrs::doc/Doc","visibility":"Public","sources":["Normal"],"mirror":true})
[2024-07-12T09:22:47.475Z INFO /Users/pattobrien/.asdf/installs/rust/1.79.0/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.1.0/src/library/codegen/parser/hir/flat/transformer/merge_duplicate_transformer/mod.rs:72] There are still multiple objects with same key after merging, thus randomly pick one. This is an issue only if the object is indeed used. (key="Options", objects={"name":"yrs::doc/Options","visibility":"Public","sources":["Normal"],"mirror":true}, {"name":"yrs::undo/Options","visibility":"Public","sources":["Normal"],"mirror":true})
[2024-07-12T09:22:47.475Z INFO /Users/pattobrien/.asdf/installs/rust/1.79.0/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.1.0/src/library/codegen/parser/hir/flat/transformer/merge_duplicate_transformer/mod.rs:72] There are still multiple objects with same key after merging, thus randomly pick one. This is an issue only if the object is indeed used. (key="Event", objects={"name":"yrs::sync::awareness/Event","visibility":"Public","sources":["Normal"],"mirror":true}, {"name":"yrs::undo/Event","visibility":"Public","sources":["Normal"],"mirror":true})
[2024-07-12T09:22:47.475Z INFO /Users/pattobrien/.asdf/installs/rust/1.79.0/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.1.0/src/library/codegen/parser/hir/flat/transformer/merge_duplicate_transformer/mod.rs:72] There are still multiple objects with same key after merging, thus randomly pick one. This is an issue only if the object is indeed used. (key="Iter", objects={"name":"yrs::types/Iter","visibility":"Restricted","sources":["Normal"],"mirror":true}, {"name":"yrs::branch/Iter","visibility":"Restricted","sources":["Normal"],"mirror":true})
[2024-07-12T09:22:47.476Z INFO /Users/pattobrien/.asdf/installs/rust/1.79.0/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.1.0/src/library/codegen/parser/hir/flat/transformer/merge_duplicate_transformer/mod.rs:72] There are still multiple objects with same key after merging, thus randomly pick one. This is an issue only if the object is indeed used. (key="Error", objects={"name":"yrs::encoding::read/Error","visibility":"Public","sources":["Normal"],"mirror":true}, {"name":"yrs::sync::awareness/Error","visibility":"Public","sources":["Normal"],"mirror":true}, {"name":"yrs::sync::protocol/Error","visibility":"Public","sources":["Normal"],"mirror":true})
[2024-07-12T09:22:47.491Z INFO /Users/pattobrien/.asdf/installs/rust/1.79.0/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.1.0/src/library/codegen/parser/mir/parser/ty/enum_or_struct.rs:73] Skip parsing enum_or_struct `NamespacedName { namespace: Namespace { joined_path: "yrs::sync::protocol" }, name: "DefaultProtocol" }` because of error (e=struct with unit fields are not supported yet, what about using `struct DefaultProtocol {}` or `#[frb(opaque)] struct DefaultProtocol;` instead

Stack backtrace:
   0: std::backtrace::Backtrace::create
   1: anyhow::error::<impl anyhow::Error>::msg
   2: lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::ty::structure::<impl lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::ty::TypeParserWithContext>::parse_struct
   3: lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::ty::enum_or_struct::EnumOrStructParser::parse
   4: lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::ty::path::<impl lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::ty::TypeParserWithContext>::parse_type_path
   5: lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::ty::ty::<impl lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::ty::TypeParserWithContext>::parse_type
   6: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
   7: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
   8: core::iter::adapters::try_process
   9: lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::trait_impl::parse
  10: lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::parse
  11: lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parse
  12: lib_flutter_rust_bridge_codegen::library::codegen::parser::early_generator::execute
  13: lib_flutter_rust_bridge_codegen::library::codegen::generate_once
  14: lib_flutter_rust_bridge_codegen::library::codegen::controller::run
  15: lib_flutter_rust_bridge_codegen::library::codegen::generate
  16: flutter_rust_bridge_codegen::main
  17: std::sys_common::backtrace::__rust_begin_short_backtrace
  18: std::rt::lang_start::{{closure}}
  19: std::rt::lang_start_internal
  20: _main)
[2024-07-12T09:22:47.524Z INFO /Users/pattobrien/.asdf/installs/rust/1.79.0/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.1.0/src/library/codegen/parser/mir/parser/ty/enum_or_struct.rs:73] Skip parsing enum_or_struct `NamespacedName { namespace: Namespace { joined_path: "yrs::block" }, name: "Unused" }` because of error (e=struct with unit fields are not supported yet, what about using `struct Unused {}` or `#[frb(opaque)] struct Unused;` instead

Stack backtrace:
   0: std::backtrace::Backtrace::create
   1: anyhow::error::<impl anyhow::Error>::msg
   2: lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::ty::structure::<impl lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::ty::TypeParserWithContext>::parse_struct
   3: lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::ty::enum_or_struct::EnumOrStructParser::parse
   4: lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::ty::path::<impl lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::ty::TypeParserWithContext>::parse_type_path
   5: lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::ty::ty::<impl lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::ty::TypeParserWithContext>::parse_type
   6: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
   7: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
   8: core::iter::adapters::try_process
   9: lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::trait_impl::parse
  10: lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parser::parse
  11: lib_flutter_rust_bridge_codegen::library::codegen::parser::mir::parse
  12: lib_flutter_rust_bridge_codegen::library::codegen::parser::early_generator::execute
  13: lib_flutter_rust_bridge_codegen::library::codegen::generate_once
  14: lib_flutter_rust_bridge_codegen::library::codegen::controller::run
  15: lib_flutter_rust_bridge_codegen::library::codegen::generate
  16: flutter_rust_bridge_codegen::main
  17: std::sys_common::backtrace::__rust_begin_short_backtrace
  18: std::rt::lang_start::{{closure}}
  19: std::rt::lang_start_internal
  20: _main)
[2024-07-12T09:22:47.526Z ERROR /Users/pattobrien/.asdf/installs/rust/1.79.0/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.1.0/src/library/utils/logs.rs:55] panicked at /Users/pattobrien/.asdf/installs/rust/1.79.0/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.1.0/src/library/codegen/ir/mir/ty/structure.rs:36:32:
no entry found for key=MirStructIdent(NamespacedName { namespace: Namespace { joined_path: "yrs::sync::protocol" }, name: "DefaultProtocol" })

Expected behavior

I would've expected two different outcomes:

  • that no error is seen (i.e. support for unit structs)
  • that I'm able to easily overwrite / ignore a particular struct or module from the config, in order to temporarily workaround the bug

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

pattobrien avatar Jul 12 '24 09:07 pattobrien