-
Notifications
You must be signed in to change notification settings - Fork 490
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: deriving Destruct leads to 'Internal error, cycle detected:` panic #3943
Comments
It also looks like there might be a problem when we create a type T that implements destruct and put it in a box (which is what I'm trying to do originally in my codebase) the following code will not compile because Destruct<Box> is not implemented #[derive(Destruct)]
struct InnerStruct {// dict: Felt252Dict<u128>
}
#[derive(Destruct)]
struct OuterStruct {
dict: Felt252Dict<u128>,
inner: Box<InnerStruct>
}
fn execute() {
let mut ctx = OuterStruct { dict: Default::default(), inner: BoxTrait::new(InnerStruct {}) };
} so, I add an implementation of destruct for it following @orizi's advice in #3854 struct InnerStruct {}
impl DestructBoxInnerStruct of Destruct<Box<InnerStruct>> {
fn destruct(self: Box<InnerStruct>) nopanic {}
}
#[derive(Destruct)]
struct OuterStruct {
dict: Felt252Dict<u128>,
inner: Box<InnerStruct>
}
fn execute() {
let mut ctx = OuterStruct { dict: Default::default(), inner: BoxTrait::new(InnerStruct {}) };
} And same error: thread 'main' panicked at 'Internal error, cycle detected:
DatabaseKeyIndex { group_index: 5, query_index: 16, key_index: 1 }
DatabaseKeyIndex { group_index: 5, query_index: 15, key_index: 2 }
DatabaseKeyIndex { group_index: 5, query_index: 14, key_index: 2 }
', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/salsa-0.16.1/src/lib.rs:490:48
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace |
do note that the destruct implementation is wrong - but the compiler panic is indeed bad:
|
Thanks for the correction! The compiler still panics if the struct is empty. But with your right destruct implementation, it fixed my original problem 😉 use box::BoxTrait;
use traits::Destruct;
#[derive(Destruct)]
struct InnerStruct {}
impl DestructBoxInnerStruct of Destruct<Box<InnerStruct>> {
fn destruct(self: Box<InnerStruct>) nopanic {
self.unbox().destruct()
}
}
#[derive(Destruct)]
struct OuterStruct {
dict: Felt252Dict<u128>,
inner: Box<InnerStruct>
}
fn execute() {
let mut ctx = OuterStruct { dict: Default::default(), inner: BoxTrait::new(InnerStruct {}) };
} |
Bug Report
Cairo version:
1f83b95
Current behavior:
Compiling the code below leads to the following error:
Expected behavior:
The code compiles successfully
Steps to reproduce:
Compile the following code
Other information:
The bug seems to be related to the
Destruct
derivation. Removing it and replacing it byDrop
works fine. However, this is just a minimal reproducible example I've been able to build. In my real use case, I have struct containing a Dict, and thus I cannot derive Drop.The text was updated successfully, but these errors were encountered: