-
Notifications
You must be signed in to change notification settings - Fork 300
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
Panic on codegen "Parse HIR" phase when defining private type #2170
Comments
Firstly, yes it should never panic. (e.g. it can return a Result::Err, and later that err is ignored). Feel free to PR for this by e.g. converting a panic into a Result::Err! Alternatively, I will work on it in the next batch. Secondly, as for why it sees it: I have not implemented full-featured module parsing logic, since the rule of "what module is visible" is not very trivial. But feel free to PR for this as well. The non-api folder is scanned because there can be definitions in non-api folders and is used in api folders, so in this phase we just parse it. Thirdly, the current workaround, as you pointed out, is to |
Running into the same issue, how do I determine which mod I should write? flutter_rust_bridge_codegen generate
[2024-07-01T02:23:49.548Z INFO frb_codegen\src\library\codegen\parser\mir\parser\ty\enum_or_struct.rs:73] Skip parsing enum_or_struct `NamespacedName { namespace: Namespace { joined_path: "crate::bls::bls12381::big" }, name: "BIG" }` because of error (e=Cannot parse array length
Stack backtrace:
0: <unknown>
1: <unknown>
2: <unknown>
3: <unknown>
4: <unknown>
5: <unknown>
6: <unknown>
7: <unknown>
8: <unknown>
9: <unknown>
10: <unknown>
11: <unknown>
12: <unknown>
13: <unknown>
14: <unknown>
15: <unknown>
16: <unknown>
17: <unknown>
18: <unknown>
19: <unknown>
20: <unknown>
21: <unknown>
22: <unknown>
23: <unknown>
24: <unknown>
25: <unknown>
26: BaseThreadInitThunk
27: RtlUserThreadStart)
[2024-07-01T02:23:49.550Z INFO frb_codegen\src\library\codegen\parser\mir\parser\ty\enum_or_struct.rs:73] Skip parsing enum_or_struct `NamespacedName { namespace: Namespace { joined_path: "crate::bls::bls12381::dbig" }, name: "DBIG" }` because of error (e=Cannot parse array length
Stack backtrace:
0: <unknown>
1: <unknown>
2: <unknown>
3: <unknown>
4: <unknown>
5: <unknown>
6: <unknown>
7: <unknown>
8: <unknown>
9: <unknown>
10: <unknown>
11: <unknown>
12: <unknown>
13: <unknown>
14: <unknown>
15: <unknown>
16: <unknown>
17: <unknown>
18: <unknown>
19: <unknown>
20: <unknown>
21: <unknown>
22: <unknown>
23: <unknown>
24: <unknown>
25: <unknown>
26: BaseThreadInitThunk
27: RtlUserThreadStart)
[1.2s] Parse ⢀
└── [1.2s] Cargo expand & syn parse
└── [0.0s] Parse HIR
└── [0.0s] Parse MIR ⠂
[2024-07-01T02:23:49.552Z ERROR frb_codegen\src\library\utils\logs.rs:55] panicked at frb_codegen\src\library\codegen\parser\mir\parser\ty\trait_object.rs:48:38:
called `Option::unwrap()` on a `None` value
thread 'main' panicked at frb_codegen\src\library\codegen\parser\mir\parser\ty\trait_object.rs:48:38:
called `Option::unwrap()` on a `None` value
stack backtrace:
0: 0x7ff74f6751da - <unknown>
1: 0x7ff74f6931cb - <unknown>
2: 0x7ff74f66fec1 - <unknown>
3: 0x7ff74f674f5a - <unknown>
4: 0x7ff74f677dea - <unknown>
5: 0x7ff74f677a58 - <unknown>
6: 0x7ff74f57d3a7 - <unknown>
7: 0x7ff74f678629 - <unknown>
8: 0x7ff74f678332 - <unknown>
9: 0x7ff74f675e99 - <unknown>
10: 0x7ff74f678090 - <unknown>
11: 0x7ff75005e887 - <unknown>
12: 0x7ff75005e942 - <unknown>
13: 0x7ff74f8251c3 - <unknown>
14: 0x7ff74f81d42f - <unknown>
15: 0x7ff74f82401e - <unknown>
16: 0x7ff74f822d19 - <unknown>
17: 0x7ff74f72cad8 - <unknown>
18: 0x7ff74f88d9d5 - <unknown>
19: 0x7ff74f82224f - <unknown>
20: 0x7ff74f5c24db - <unknown>
21: 0x7ff74f81e16a - <unknown>
22: 0x7ff74f82401e - <unknown>
23: 0x7ff74f7bd9b3 - <unknown>
24: 0x7ff74f733d93 - <unknown>
25: 0x7ff74f8aa796 - <unknown>
26: 0x7ff74f82709d - <unknown>
27: 0x7ff74f5ed0ca - <unknown>
28: 0x7ff74f5f0711 - <unknown>
29: 0x7ff74f566149 - <unknown>
30: 0x7ff74f5eeb8c - <unknown>
31: 0x7ff74f50c78e - <unknown>
32: 0x7ff74f50b8c6 - <unknown>
33: 0x7ff74f510eda - <unknown>
34: 0x7ff74f667428 - <unknown>
35: 0x7ff74f50cd8c - <unknown>
36: 0x7ff750059e9c - <unknown>
37: 0x7ffaeb3d257d - BaseThreadInitThunk
38: 0x7ffaebe4af28 - RtlUserThreadStart |
Currently, the workaround maybe just bisect the modules (ignore half mods, see whether it works, etc)... But after it is fixed, there is no need to do so (since it will not error). Feel free to PR for this (possibly simple change)! Alternatively I will work on it in the next batch. |
Given the error is related to |
Bisected the minimal struct that can reproduce this issue: use std::fmt;
use std::fmt::Debug;
/// Trait that logs at level INFO every update received (if any).
pub trait Progress: Send + Sync + 'static {
/// Send a new progress update. The progress value should be in the range 0.0 - 100.0, and the message value is an
/// optional text message that can be displayed to the user.
fn update(&self, progress: f32, message: Option<String>);
}
pub struct ProgressHolder {
pub progress: Box<dyn Progress>,
}
impl Debug for ProgressHolder {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ProgressHolder").finish_non_exhaustive()
}
} |
Looks like |
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. |
Describe the bug
The codegen panics when I execute the steps described below.
What I find surprising is that:
struct
nor the 2traits
are pub.common.rs
is not imported bypub mod
but bymod
rust/src/api/simple.rs
is unchanged from the defaultgreet
function, and does not references in any way my struct or my traitsfrb_codegen shouldn't even see my file
common.rs
, no ?Tentatives
#[frb(ignore)]
to every item in
common.rs
, codegen still fails#[frb(ignore)]
abovemod common;
codegen succeed, but Rust compilation fails withWorking versions
rust/src/lib.rs
, codegen succeedAny help is appreciated, I thanks again for your work 👍
Steps to reproduce
From the repo created by
flutter_rust_bridge_codegen create
, I add a filerust/src/common.rs
and add this file to the crate:
Logs
Details
Expected behavior
frb_codegen should never panic.
Some restriction may apply on the type and traits that I expose to Dart, but Rust code that stay private should not have any impact on codegen
Generated binding code
No response
OS
Debian GNU/Linux 12 (bookworm)
Version of
flutter_rust_bridge_codegen
v2.0.0
Flutter info
Details
```shell [✓] Flutter (Channel stable, 3.22.2, on Debian GNU/Linux 12 (bookworm) 6.1.0-18-amd64, locale en) • Flutter version 3.22.2 on channel stable at /home/julien/fvm/versions/stable • Upstream repository https://github.com/flutter/flutter.git • Framework revision 761747bfc5 (4 weeks ago), 2024-06-05 22:15:13 +0200 • Engine revision edd8546116 • Dart version 3.4.3 • DevTools version 2.34.3
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /home/julien/Android/Sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: /home/julien/.local/share/JetBrains/Toolbox/apps/android-studio-2/jbr/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.9-11255266)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Linux toolchain - develop for Linux desktop
• Debian clang version 16.0.6 (19)
• cmake version 3.25.1
• ninja version 1.11.1
• pkg-config version 1.8.1
[✓] Android Studio (version 2023.3)
• Android Studio at /home/julien/.local/share/JetBrains/Toolbox/apps/android-studio-2
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.9-11255266)
[✓] Android Studio (version 2023.1)
• Android Studio at /home/julien/.local/share/JetBrains/Toolbox/apps/android-studio
• Flutter plugin version 78.2.1
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
[✓] Android Studio (version 2022.3)
• Android Studio at /home/julien/android-studios/android-studio-2022.3.1.19
• Flutter plugin version 75.1.2
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
[✓] IntelliJ IDEA Community Edition (version 2019.2)
• IntelliJ at /home/julien/idea
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] VS Code (version 1.87.0)
• VS Code at /usr/share/code
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (1 available)
• Linux (desktop) • linux • linux-x64 • Debian GNU/Linux 12 (bookworm) 6.1.0-18-amd64
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 2 categories.
The text was updated successfully, but these errors were encountered: