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

Panic when generating stub pymethods #69

Open
cardigan1008 opened this issue Aug 26, 2024 · 3 comments
Open

Panic when generating stub pymethods #69

cardigan1008 opened this issue Aug 26, 2024 · 3 comments

Comments

@cardigan1008
Copy link

cardigan1008 commented Aug 26, 2024

When I tried to add gen_stub_pymethods for pymethods, it panics:

thread 'main' panicked at /home/yunboni/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-stub-gen-0.6.0/src/generate/stub_info.rs:136:9:
internal error: entered unreachable code: Missing struct_id = TypeId(0xf92611a13ccd508e032c0d7de1b7a2cb)
The full backtrace
stack backtrace:
   0:     0x5a4c66ea731d - std::backtrace_rs::backtrace::libunwind::trace::hb30cb06542f0d921
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x5a4c66ea731d - std::backtrace_rs::backtrace::trace_unsynchronized::hcfaf81cd0ca679e8
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x5a4c66ea731d - std::sys::backtrace::_print_fmt::h0edd5df96f6b1838
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/sys/backtrace.rs:66:9
   3:     0x5a4c66ea731d - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h4178db4b62b6a7c8
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/sys/backtrace.rs:39:26
   4:     0x5a4c66ecdf4b - core::fmt::rt::Argument::fmt::hb0f91bd7c51e56a9
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/core/src/fmt/rt.rs:173:76
   5:     0x5a4c66ecdf4b - core::fmt::write::hdebf67a64074cdfd
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/core/src/fmt/mod.rs:1178:21
   6:     0x5a4c66ea3b73 - std::io::Write::write_fmt::h67b07a8971426909
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/io/mod.rs:1823:15
   7:     0x5a4c66ea84d2 - std::sys::backtrace::BacktraceLock::print::h5d391486a3405efe
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/sys/backtrace.rs:42:9
   8:     0x5a4c66ea84d2 - std::panicking::default_hook::{{closure}}::hb33c35cc1f4b50b3
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/panicking.rs:266:22
   9:     0x5a4c66ea813e - std::panicking::default_hook::h2c83543c651f3125
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/panicking.rs:293:9
  10:     0x5a4c66ea8dcf - std::panicking::rust_panic_with_hook::h48ec1454fab3e9d6
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/panicking.rs:797:13
  11:     0x5a4c66ea8ab7 - std::panicking::begin_panic_handler::{{closure}}::hdfdc79a140009172
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/panicking.rs:671:13
  12:     0x5a4c66ea7809 - std::sys::backtrace::__rust_end_short_backtrace::h5e9ef3624d34a08c
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/sys/backtrace.rs:170:18
  13:     0x5a4c66ea8744 - rust_begin_unwind
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/panicking.rs:662:5
  14:     0x5a4c66ecc123 - core::panicking::panic_fmt::h5c7dda2686e962d9
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/core/src/panicking.rs:74:14
  15:     0x5a4c66d4faf3 - pyo3_stub_gen::generate::stub_info::StubInfoBuilder::add_methods::h4c3b1ec6cdfad5b9
                               at /home/yunboni/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-stub-gen-0.6.0/src/generate/stub_info.rs:136:9
  16:     0x5a4c66d500fa - pyo3_stub_gen::generate::stub_info::StubInfoBuilder::build::h7444c13a5647ef64
                               at /home/yunboni/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-stub-gen-0.6.0/src/generate/stub_info.rs:156:13
  17:     0x5a4c66633db4 - pyo3_stub_gen::generate::stub_info::StubInfo::from_pyproject_toml::hb6119ccd9486a5b3
                               at /home/yunboni/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-stub-gen-0.6.0/src/generate/stub_info.rs:14:12
  18:     0x5a4c66633bc2 - hifitime::python::stub_info::hddb0ed43e85df2d1
                               at /home/yunboni/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-stub-gen-0.6.0/src/lib.rs:174:13
  19:     0x5a4c665b03f5 - stub_gen::main::h5b6d66163ae71fe5
                               at /home/yunboni/hifitime/src/bin/stub_gen.rs:4:16
  20:     0x5a4c665b069b - core::ops::function::FnOnce::call_once::h61545b5ea0bed2b5
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/core/src/ops/function.rs:250:5
  21:     0x5a4c665b018e - std::sys::backtrace::__rust_begin_short_backtrace::h89427225118d9066
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/sys/backtrace.rs:154:18
  22:     0x5a4c665b0151 - std::rt::lang_start::{{closure}}::ha9fd5973a951ece5
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/rt.rs:164:18
  23:     0x5a4c66e9eab0 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h1aa92f19b2f91a3c
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/core/src/ops/function.rs:284:13
  24:     0x5a4c66e9eab0 - std::panicking::try::do_call::hfc6bbd2f1a3cd1f1
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/panicking.rs:554:40
  25:     0x5a4c66e9eab0 - std::panicking::try::h5620cef3d1a654de
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/panicking.rs:518:19
  26:     0x5a4c66e9eab0 - std::panic::catch_unwind::h970e31091dac502b
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/panic.rs:345:14
  27:     0x5a4c66e9eab0 - std::rt::lang_start_internal::{{closure}}::hfdfbb5d94d0b9db3
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/rt.rs:143:48
  28:     0x5a4c66e9eab0 - std::panicking::try::do_call::he3ecfdbda2953cda
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/panicking.rs:554:40
  29:     0x5a4c66e9eab0 - std::panicking::try::h363a3b12f1cc4371
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/panicking.rs:518:19
  30:     0x5a4c66e9eab0 - std::panic::catch_unwind::h83fc948c8bab08fe
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/panic.rs:345:14
  31:     0x5a4c66e9eab0 - std::rt::lang_start_internal::hc5f8e73a6e68745c
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/rt.rs:143:20
  32:     0x5a4c665b012a - std::rt::lang_start::hdef74db7328565d8
                               at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/library/std/src/rt.rs:163:17
  33:     0x5a4c665b065e - main
  34:     0x79bdf0829d90 - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  35:     0x79bdf0829e40 - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:392:3
  36:     0x5a4c665b0025 - _start
  37:                0x0 - <unknown>

The code is:

#[cfg_attr(feature = "python", gen_stub_pymethods)] // where I add the gen_stub_pymethods
#[cfg_attr(feature = "python", pymethods)]
impl TimeScale {
    /// Returns true if self takes leap seconds into account
    pub const fn uses_leap_seconds(&self) -> bool {
        matches!(self, Self::UTC)
    }
}
@termoshtt
Copy link
Collaborator

internal error: entered unreachable code: Missing struct_id = TypeId(0xf92611a13ccd508e032c0d7de1b7a2cb)

This means TimeScale does not attributed by #[gen_stub_pyclass] (or #[gen_stub_pyclass_enum])

@cardigan1008
Copy link
Author

This means TimeScale does not attributed by #[gen_stub_pyclass] (or #[gen_stub_pyclass_enum])

However, I have implemented TimeScale with #[gen_stub_pyclass_enum]:

#[cfg_attr(feature = "python", gen_stub_pyclass_enum)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "python", pyclass(eq, eq_int))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum TimeScale {

And the previous generated .pyi file has included the TimeScale class.

@termoshtt
Copy link
Collaborator

Looks strange, will be a bug. Could you create a minimal example to reproduce this result?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants