-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
thread 'rustc' panicked at 'Box<dyn Any>' #93002
Labels
C-bug
Category: This is a bug.
I-ICE
Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
nbittich
added
C-bug
Category: This is a bug.
I-ICE
Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Jan 17, 2022
Looks like the ICE is fixed on nightly and in 1.59.0-beta.1, although the diagnostic suggestion is still a bit odd:
|
Might be duplicate of #92979 |
still reproduce in rustc 1.60.0
src/lib.rs mod prelude {
pub use std::collections::HashMap;
pub use std::hash::Hash;
pub trait Lru<K: Default + Hash + Eq + Clone, V: Default> {
fn new(capacity: usize) -> Self;
unsafe fn put(&mut self, key: K, val: V);
unsafe fn get(&mut self, key: K) -> Option<V>;
}
}
use prelude::*;
struct ListNode<K, V> {
key: K,
val: V,
next: *mut ListNode<K, V>,
prev: *mut ListNode<K, V>
}
impl<K: Default, V: Default> Default for ListNode<K, V> {
fn default() -> Self {
Self {
key: K::default(),
val: V::default(),
next: std::ptr::null_mut(),
prev: std::ptr::null_mut()
}
}
}
struct LruImpl<K: Default, V: Default> {
// TODO limit linkedlist capacity
// capacity: usize
head: ListNode<K, V>,
tail: ListNode<K, V>,
cache: HashMap<K, *mut ListNode<K, V>>
}
impl<K: Default, V: Default> LruImpl<K, V> {
unsafe fn detach_node(&mut self, node: *mut ListNode<K, V>) {
// detach node
(*(*node).next).prev = (*(*node).prev).next;
(*(*node).prev).next = (*(*node).next).next;
}
/// before: head->...->node->...->tail
/// after : head->node->...->tail
unsafe fn move_node_to_head(&mut self, node: *mut ListNode<K, V>) {
// let a = (*(*node).prev).next;
// detach node
if !(*node).prev.is_null() && !(*node).next.is_null() {
self.detach_node(node);
}
// head->next connect to node
(*node).next = (*self.head.next).prev;
(*self.head.next).prev = node;
// head connect to node
self.head.next = node;
(*node).prev = &mut self.head;
}
}
impl<K: Default + Hash + Eq + Clone, V: Default + Clone> Lru<K, V> for LruImpl<K, V> {
fn new(_capacity: usize) -> Self {
let mut head = ListNode::default();
let mut tail = ListNode::default();
head.next = &mut tail;
tail.prev = &mut head;
Self {
head,
tail,
cache: HashMap::new()
}
}
unsafe fn put(&mut self, key: K, val: V) {
if let Some(node_ptr) = self.cache.get(&key) {
(*(*node_ptr)).val = val;
self.move_node_to_head(*node_ptr);
return;
}
let mut node = ListNode {
key,
val,
next: self.head.prev,
prev: &mut self.head,
};
self.cache.insert(node.key.clone(), &mut node);
}
// FIXME SIGSEGV
unsafe fn get(&mut self, key: K) -> Option<V> {
// ownership problem
// let self_ = self as *mut Self;
dbg!(line!());
if let Some(node_ptr) = self.cache.get(&key) {
dbg!(line!());
self.move_node_to_head(*node_ptr);
}
dbg!(line!());
let ret = self.cache.get(&key).map(|node_ptr| {
// (*self_).move_node_to_head(*node_ptr);
(*(*node_ptr)).val.clone()
});
ret
}
}
#[test]
fn test() {
let mut lru = LruImpl::<&'static str, &'static str>::new(10);
unsafe {
lru.put("key1", "val1");
lru.put("key2", "val2");
dbg!(lru.get("key1"));
}
} |
looks fixed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
C-bug
Category: This is a bug.
I-ICE
Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Meta
rustc --version --verbose
:Error output
Backtrace
The text was updated successfully, but these errors were encountered: