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

External specification declared on a trait implementation did not resolve to a concrete type #1515

Open
nishanthkarthik opened this issue May 27, 2024 · 0 comments

Comments

@nishanthkarthik
Copy link

nishanthkarthik commented May 27, 2024

I'm trying to test extern_spec for a TryFrom impl. parse_u32 is supposed to prove a cast from a slice to an array. The extern spec currently throws an error internal error: entered unreachable code: External specification declared on a trait implementation did not resolve to a concrete type

extern crate prusti_contracts;
use prusti_contracts::*;

#[extern_spec]
impl<T, const N: usize> std::convert::TryFrom<&[T]> for [T; N]
where T: Copy,
{
    #[inline]
    // <Specifications removed here>
    fn try_from(slice: &[T]) -> Result<[T; N], std::array::TryFromSliceError>;
}

#[requires(a.len() == 4)]
fn parse_u32(a: &[u8]) -> u32 {
    let bytes: Result<[u8; 4], _> = std::convert::TryFrom::try_from(a);
    match bytes {
        Ok(x) => u32::from_le_bytes(x),
        Err(_) => {
            prusti_assert!(false);
            0
        },
    }
}

My goal is to specify try_from such that the assert-false is not triggered. Currently, prusti fails with an ICE

stacktrace
thread 'rustc' panicked at prusti-interface/src/specs/external.rs:155:17:
internal error: entered unreachable code: External specification declared on a trait implementation did not resolve to a concrete type
stack backtrace:
   0:     0x792da1362efc - std::backtrace_rs::backtrace::libunwind::trace::h652247f520429b18
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x792da1362efc - std::backtrace_rs::backtrace::trace_unsynchronized::h20ba733a518048ae
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x792da1362efc - std::sys_common::backtrace::_print_fmt::ha9cb2d71bba5eb16
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x792da1362efc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h527f3c0db321cf86
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x792da13c915c - core::fmt::rt::Argument::fmt::hc5a8cd063e05c609
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/core/src/fmt/rt.rs:138:9
   5:     0x792da13c915c - core::fmt::write::h818c732e4e373aa5
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/core/src/fmt/mod.rs:1094:21
   6:     0x792da1355b1e - std::io::Write::write_fmt::h9fe6c7e095e96a32
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/std/src/io/mod.rs:1714:15
   7:     0x792da1362ce4 - std::sys_common::backtrace::_print::h4b50c3b478ae2a37
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x792da1362ce4 - std::sys_common::backtrace::print::hf2c7643f5414af94
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x792da1365dda - std::panicking::panic_hook_with_disk_dump::{{closure}}::h62ff4ef3ec32306d
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/std/src/panicking.rs:280:22
  10:     0x792da1365a98 - std::panicking::panic_hook_with_disk_dump::hcd58ca7cb67f8702
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/std/src/panicking.rs:307:9
  11:     0x792da45690b9 - <rustc_driver_impl[8b2874cda94e7cd4]::install_ice_hook::{closure#0} as core[b0493a3e457862f3]::ops::function::FnOnce<(&core[b0493a3e457862f3]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  12:     0x792da1366693 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h2b79b1e8b8bd4402
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/alloc/src/boxed.rs:2021:9
  13:     0x792da1366693 - std::panicking::rust_panic_with_hook::ha2c93276d1208654
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/std/src/panicking.rs:757:13
  14:     0x792da13663c6 - std::panicking::begin_panic_handler::{{closure}}::hb78d7a76234f0397
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/std/src/panicking.rs:623:13
  15:     0x792da1363426 - std::sys_common::backtrace::__rust_end_short_backtrace::h96e02fd19b415b36
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x792da1366152 - rust_begin_unwind
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/std/src/panicking.rs:619:5
  17:     0x792da13c5505 - core::panicking::panic_fmt::h62ee289ca1991433
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/core/src/panicking.rs:72:14
  18:     0x60b11d35a8f2 - prusti_interface::specs::external::ExternSpecResolver::add_extern_fn::hbd4b0f6255a4e2fc
  19:     0x60b11d36369e - <prusti_interface::specs::SpecCollector as rustc_hir::intravisit::Visitor>::visit_fn::h1c00a4816b11d7be
  20:     0x60b11d32443c - rustc_hir::intravisit::walk_item::h0bee9e35ac9a576c
  21:     0x60b11d38f594 - prusti_interface::specs::SpecCollector::collect_specs::h4dc91f6926130477
  22:     0x60b11ca2419d - <prusti_driver::callbacks::PrustiCompilerCalls as rustc_driver_impl::Callbacks>::after_analysis::h7d8f5df69404394f
  23:     0x792da3a789d6 - <rustc_interface[1527d435bc9889c9]::interface::Compiler>::enter::<rustc_driver_impl[8b2874cda94e7cd4]::run_compiler::{closure#1}::{closure#2}, core[b0493a3e457862f3]::result::Result<core[b0493a3e457862f3]::option::Option<rustc_interface[1527d435bc9889c9]::queries::Linker>, rustc_span[82af0e0afe7e8690]::ErrorGuaranteed>>
  24:     0x792da3a71c04 - std[843b1ee06368cddb]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[1527d435bc9889c9]::util::run_in_thread_with_globals<rustc_interface[1527d435bc9889c9]::interface::run_compiler<core[b0493a3e457862f3]::result::Result<(), rustc_span[82af0e0afe7e8690]::ErrorGuaranteed>, rustc_driver_impl[8b2874cda94e7cd4]::run_compiler::{closure#1}>::{closure#0}, core[b0493a3e457862f3]::result::Result<(), rustc_span[82af0e0afe7e8690]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b0493a3e457862f3]::result::Result<(), rustc_span[82af0e0afe7e8690]::ErrorGuaranteed>>
  25:     0x792da3a7135e - <<std[843b1ee06368cddb]::thread::Builder>::spawn_unchecked_<rustc_interface[1527d435bc9889c9]::util::run_in_thread_with_globals<rustc_interface[1527d435bc9889c9]::interface::run_compiler<core[b0493a3e457862f3]::result::Result<(), rustc_span[82af0e0afe7e8690]::ErrorGuaranteed>, rustc_driver_impl[8b2874cda94e7cd4]::run_compiler::{closure#1}>::{closure#0}, core[b0493a3e457862f3]::result::Result<(), rustc_span[82af0e0afe7e8690]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b0493a3e457862f3]::result::Result<(), rustc_span[82af0e0afe7e8690]::ErrorGuaranteed>>::{closure#1} as core[b0493a3e457862f3]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  26:     0x792da1371075 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7bff668e3fcc7cec
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/alloc/src/boxed.rs:2007:9
  27:     0x792da1371075 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6cf1c11e2e0c58d1
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/alloc/src/boxed.rs:2007:9
  28:     0x792da1371075 - std::sys::unix::thread::Thread::new::thread_start::hfa7d5fcc9039f5da
                               at /rustc/ca2b74f1ae5075d62e223c0a91574a1fc3f51c7c/library/std/src/sys/unix/thread.rs:108:17
  29:     0x792d9fdbbded - <unknown>
  30:     0x792d9fe3f0dc - <unknown>
  31:                0x0 - <unknown>


rustc version: 1.74.0-nightly (ca2b74f1a 2023-09-14)
platform: x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
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

1 participant