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

bug: Program creating Nullable<Box<u32>> panics during execution #5411

Closed
fmoletta opened this issue Apr 12, 2024 · 3 comments · Fixed by #5416
Closed

bug: Program creating Nullable<Box<u32>> panics during execution #5411

fmoletta opened this issue Apr 12, 2024 · 3 comments · Fixed by #5416
Labels
bug Something isn't working

Comments

@fmoletta
Copy link

Bug Report

Cairo version: v2.6.3 (Commit 2203a47)

Current behavior:
Running the cairo program in the Related Code section using cairo-run returns panics with:

thread 'main' panicked at crates/cairo-lang-sierra-generator/src/utils.rs:212:21:
internal error: entered unreachable code: Should be handled by `const_libfunc_id_by_type`.

Expected behavior:

The program should run like it used to in v2.5.4, returning :
Run completed successfully, returning [10]

Steps to reproduce:

Create a file with the code in the Related Code section and run it using:
cargo run --bin cairo-run -- --single-file program.cairo

Related code:

fn main() -> Nullable<Box<u32>> {
    nullable_from_box(BoxTrait::new(BoxTrait::new(16)))
}

Other information:

@fmoletta fmoletta added the bug Something isn't working label Apr 12, 2024
@fmoletta
Copy link
Author

Small Update: Running the same program using NullableTrait::new instead of nullable_from_box directly also yields the same error:

use core::nullable::NullableTrait;

fn main() -> Nullable<Box<u32>> {
    NullableTrait::<Box<u32>>::new(BoxTrait::new(16))
}
thread 'main' panicked at crates/cairo-lang-sierra-generator/src/utils.rs:212:21:
internal error: entered unreachable code: Should be handled by `const_libfunc_id_by_type`

@orizi orizi linked a pull request Apr 13, 2024 that will close this issue
@orizi
Copy link
Collaborator

orizi commented Apr 13, 2024

thanks for reporting.
Attached PR fixes it. Can be handled locally for the time being by change the code to any of these:

/// The helper
#[inline(never)]
fn identity<T>(t: T) -> T { t }
...
NullableTrait::<Box<u32>>::new(BoxTrait::new(identity(16)))
NullableTrait::<Box<u32>>::new(identity(BoxTrait::new(16)))

@bmmoore
Copy link

bmmoore commented Jul 4, 2024

In case anyone else runs into it, this error can also be seen at compile time - and is fixed in 2.7.0-rc0. Here is minimized code where we were seeing the same internal error during scarb build (with asdf-installed scarb 2.6.5)

pub enum Pattern { Leaf, Boxed: Box<Pattern>, }
pub fn cbox(subpattern: Pattern) -> Pattern {
    return Pattern::Boxed(BoxTrait::new(subpattern));
}
pub fn fail() -> Pattern {
     return cbox(cbox(Pattern::Leaf));
}
   Compiling ml_checker_cairo v0.1.0 (/home/brandon/code/proof-checker-public/cairo/Scarb.toml)
thread 'main' panicked at /cargo/registry/src/index.crates.io-6f17d22bba15001f/cairo-lang-sierra-generator-2.6.4/src/utils.rs:212:21:
internal error: entered unreachable code: Should be handled by `const_libfunc_id_by_type`.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants