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

implicit_constructors.rs panic due to lack of parameters #923

Closed
adetaylor opened this issue Mar 14, 2022 · 2 comments · Fixed by #927
Closed

implicit_constructors.rs panic due to lack of parameters #923

adetaylor opened this issue Mar 14, 2022 · 2 comments · Fixed by #927

Comments

@adetaylor
Copy link
Collaborator

adetaylor commented Mar 14, 2022

I added #922 as a bit of a stress test.

It reports this panic...

thread 'integration_test::test_generate_all_string' panicked at 'called `Option::unwrap()` on a `None` value', engine/src/conversion/analysis/fun/implicit_constructors.rs:576:30
stack backtrace:
   0: rust_begin_unwind
             at /rustc/e95b10ba4ac4564ed25f7eef143e3182c33b3902/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/e95b10ba4ac4564ed25f7eef143e3182c33b3902/library/core/src/panicking.rs:143:14
   2: core::panicking::panic
             at /rustc/e95b10ba4ac4564ed25f7eef143e3182c33b3902/library/core/src/panicking.rs:48:5
   3: core::option::Option<T>::unwrap
             at /rustc/e95b10ba4ac4564ed25f7eef143e3182c33b3902/library/core/src/option.rs:752:21
   4: autocxx_engine::conversion::analysis::fun::implicit_constructors::find_explicit_items
             at /home/runner/work/autocxx/autocxx/engine/src/conversion/analysis/fun/implicit_constructors.rs:573:52
   5: autocxx_engine::conversion::analysis::fun::implicit_constructors::find_constructors_present
             at /home/runner/work/autocxx/autocxx/engine/src/conversion/analysis/fun/implicit_constructors.rs:176:21
   6: autocxx_engine::conversion::analysis::fun::FnAnalyzer::add_constructors_present
             at /home/runner/work/autocxx/autocxx/engine/src/conversion/analysis/fun/mod.rs:1802:31
   7: autocxx_engine::conversion::analysis::fun::FnAnalyzer::analyze_functions
             at /home/runner/work/autocxx/autocxx/engine/src/conversion/analysis/fun/mod.rs:310:27
   8: autocxx_engine::conversion::BridgeConverter::convert
             at /home/runner/work/autocxx/autocxx/engine/src/conversion/mod.rs:157:21
   9: autocxx_engine::IncludeCppEngine::generate
             at /home/runner/work/autocxx/autocxx/engine/src/lib.rs:387:26
  10: autocxx_engine::parse_file::ParsedFile::resolve_all
             at /home/runner/work/autocxx/autocxx/engine/src/parse_file.rs:363:13
  11: autocxx_engine::builder::Builder<CTX>::build_listing_files
             at /home/runner/work/autocxx/autocxx/engine/src/builder.rs:224:9
  12: autocxx_integration_tests::do_run_test_manual
             at ./src/lib.rs:355:25
  13: autocxx_integration_tests::do_run_test
             at ./src/lib.rs:295:5
  14: autocxx_integration_tests::run_test_ex
             at ./src/lib.rs:180:5
  15: integration_tests::integration_test::test_generate_all_string::test_impl
             at ./tests/integration_test.rs:5899:5
  16: integration_tests::integration_test::test_generate_all_string
             at ./tests/integration_test.rs:5887:1
  17: integration_tests::integration_test::test_generate_all_string::{{closure}}
             at ./tests/integration_test.rs:5887:1
  18: core::ops::function::FnOnce::call_once
             at /rustc/e95b10ba4ac4564ed25f7eef143e3182c33b3902/library/core/src/ops/function.rs:227:5
  19: core::ops::function::FnOnce::call_once
             at /rustc/e95b10ba4ac4564ed25f7eef143e3182c33b3902/library/core/src/ops/function.rs:227:5

This appears to be because the implicit_constructor logic has found a SpecialMemberKind::AssignmentOperator with no recorded parameters in the param_details variable.

It's not clear to me why we're recording no parameters for this function. I'll look into it unless @bsilver8192 gets there first...

@bsilver8192
Copy link
Contributor

I'm looking now.

@bsilver8192
Copy link
Contributor

We're declaring something an assignment operator before realizing that we want nothing to do with it because the name is a reserved identifier (double underscores). Those types should get treated as "we don't know what implicit special member functions they have, and we'll ignore the explicit ones that couldn't be parsed, and only look at any other explicit ones". PR coming soon.

My notes on how I got there, for future-me or anybody else:

It's having trouble with nonesuch. Ironically this is an experimental part of the C++ standard library that has something to do with detecting whether a type has special member functions. cppreference says it's can't be copied, and autocxx is choking on an operator_equals with no arguments.

bindgen emits this:

            #[repr(C)]
            #[cpp_semantics(layout(1, 1, false))]
            pub struct __nonesuch {
                pub _address: u8,
            }
            extern "C" {
                #[cpp_semantics(arg_type_reference(arg1))]
                #[cpp_semantics(original_name("operator_equals"))]
                #[cpp_semantics(special_member("assignment_operator"))]
                #[cpp_semantics(deleted)]
                #[link_name = "\u{1}_ZNSt10__nonesuchaSERKS_"]
                pub fn __nonesuch_operator_equals(
                    this: *mut root::std::__nonesuch,
                    arg1: *const root::std::__nonesuch,
                );
            }
            extern "C" {
                #[cpp_semantics(original_name("__nonesuch"))]
                #[cpp_semantics(special_member("default_ctor"))]
                #[cpp_semantics(deleted)]
                #[link_name = "\u{1}_ZNSt10__nonesuchC1Ev"]
                pub fn __nonesuch___nonesuch(this: *mut root::std::__nonesuch);
            }
            extern "C" {
                #[cpp_semantics(arg_type_reference(arg1))]
                #[cpp_semantics(original_name("__nonesuch"))]
                #[cpp_semantics(special_member("copy_ctor"))]
                #[cpp_semantics(deleted)]
                #[link_name = "\u{1}_ZNSt10__nonesuchC1ERKS_"]
                pub fn __nonesuch___nonesuch1(
                    this: *mut root::std::__nonesuch,
                    arg1: *const root::std::__nonesuch,
                );
            }
            extern "C" {
                #[cpp_semantics(original_name("__nonesuch_destructor"))]
                #[cpp_semantics(special_member("dtor"))]
                #[cpp_semantics(deleted)]
                #[link_name = "\u{1}_ZNSt10__nonesuchD1Ev"]
                pub fn __nonesuch___nonesuch_destructor(this: *mut root::std::__nonesuch);
            }
            impl __nonesuch {
                #[cpp_semantics(arg_type_reference(arg1))]
                #[inline]
                pub unsafe fn operator_equals(&mut self, arg1: *const root::std::__nonesuch) {
                    __nonesuch_operator_equals(self, arg1)
                }
                #[inline]
                pub unsafe fn new() -> Self {
                    let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
                    __nonesuch___nonesuch(__bindgen_tmp.as_mut_ptr());
                    __bindgen_tmp.assume_init()
                }
                #[cpp_semantics(arg_type_reference(arg1))]
                #[inline]
                pub unsafe fn new1(arg1: *const root::std::__nonesuch) -> Self {
                    let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
                    __nonesuch___nonesuch1(__bindgen_tmp.as_mut_ptr(), arg1);
                    __bindgen_tmp.assume_init()
                }
                #[inline]
                pub unsafe fn destruct(&mut self) {
                    __nonesuch___nonesuch_destructor(self)
                }
            }

The function is deleted, so autocxx should be ignoring it... Autocxx also tries to ignore the whole type, which seems reasonable:

Ignored item __nonesuch: Names containing __ are reserved by C++ so not acceptable to cxx

fun.inputs has the arguments, as expected.

convert_fn_arg returns Err(TooManyUnderscores) for both of the arguments, so they end up filtered out. But it ends up with SpecialMemberKind::AssignmentOperator because we check that before checking bads.

bsilver8192 added a commit to bsilver8192/autocxx that referenced this issue Mar 17, 2022
This should also gracefully handle other reasons for ignoring assignment
operator overloads.

Fixes google#923
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

Successfully merging a pull request may close this issue.

2 participants