Skip to content

Commit

Permalink
fix miri failures
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev committed Apr 13, 2024
1 parent 2f65dda commit b34292c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
46 changes: 16 additions & 30 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,15 +1020,11 @@ where
// the new bin will also be a tree bin. if both the high
// bin and the low bin are non-empty, we have to
// allocate a new TreeBin.
Shared::boxed(
BinEntry::Tree(TreeBin::new(
// safety: we have just created `low` and its `next`
// nodes and have never shared them
unsafe { low.into_box() },
guard,
)),
&self.collector,
)
// safety: we have just created `low` and its `next` nodes using `Shared::boxed`
// and have never shared them
let low_bin = unsafe { BinEntry::Tree(TreeBin::new(low.as_ptr(), guard)) };

Check warning on line 1025 in src/map.rs

View check run for this annotation

Codecov / codecov/patch

src/map.rs#L1025

Added line #L1025 was not covered by tests

Shared::boxed(low_bin, &self.collector)

Check warning on line 1027 in src/map.rs

View check run for this annotation

Codecov / codecov/patch

src/map.rs#L1027

Added line #L1027 was not covered by tests
} else {
// if not, we can re-use the old bin here, since it will
// be swapped for a Moved entry while we are still
Expand All @@ -1048,15 +1044,12 @@ where
unsafe { TreeBin::drop_tree_nodes(high, false, guard) };
high_linear
} else if low_count != 0 {
Shared::boxed(
BinEntry::Tree(TreeBin::new(
// safety: we have just created `high` and its `next`
// nodes and have never shared them
unsafe { high.into_box() },
guard,
)),
&self.collector,
)
// safety: we have just created `high` and its `next` nodes using `Shared::boxed`
// and have never shared them
let high_bin =
unsafe { BinEntry::Tree(TreeBin::new(high.as_ptr(), guard)) };

Check warning on line 1050 in src/map.rs

View check run for this annotation

Codecov / codecov/patch

src/map.rs#L1049-L1050

Added lines #L1049 - L1050 were not covered by tests

Shared::boxed(high_bin, &self.collector)

Check warning on line 1052 in src/map.rs

View check run for this annotation

Codecov / codecov/patch

src/map.rs#L1052

Added line #L1052 was not covered by tests
} else {
reused_bin = true;
// since we also don't use the created low nodes here,
Expand Down Expand Up @@ -2793,18 +2786,11 @@ where
tail = new_tree_node;
e = e_deref.next.load(Ordering::SeqCst, guard);
}
tab.store_bin(
index,
Shared::boxed(
BinEntry::Tree(TreeBin::new(
// safety: we have just created `head` and its `next`
// nodes and have never shared them
unsafe { head.into_box() },
guard,
)),
&self.collector,
),
);

// safety: we have just created `head` and its `next` nodes using `Shared::boxed`
// and have never shared them
let head_bin = unsafe { BinEntry::Tree(TreeBin::new(head.as_ptr(), guard)) };
tab.store_bin(index, Shared::boxed(head_bin, &self.collector));
drop(lock);
// make sure the old bin entries get dropped
e = bin;
Expand Down
8 changes: 6 additions & 2 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,13 @@ where
/// Constructs a new bin from the given nodes.
///
/// Nodes are arranged into an ordered red-black tree.
pub(crate) fn new(bin: Box<Linked<BinEntry<K, V>>>, guard: &Guard<'_>) -> Self {
///
/// # Safety
///
/// The `bin` pointer was created from a `Box` and never shared.
pub(crate) unsafe fn new(bin: *mut Linked<BinEntry<K, V>>, guard: &Guard<'_>) -> Self {
let mut root = Shared::null();
let bin = Shared::from(Box::into_raw(bin));
let bin = Shared::from(bin);

// safety: We own the nodes for creating this new TreeBin, so they are
// not shared with another thread and cannot get invalidated.
Expand Down

0 comments on commit b34292c

Please sign in to comment.