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 8ae16b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
45 changes: 15 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, 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,11 @@ 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, guard)) };

Check warning on line 1049 in src/map.rs

View check run for this annotation

Codecov / codecov/patch

src/map.rs#L1049

Added line #L1049 was not covered by tests

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

Check warning on line 1051 in src/map.rs

View check run for this annotation

Codecov / codecov/patch

src/map.rs#L1051

Added line #L1051 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 +2785,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, 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
7 changes: 5 additions & 2 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,12 @@ 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 with `Shared::boxed` and never shared.
pub(crate) unsafe fn new(bin: Shared<'_, BinEntry<K, V>>, guard: &Guard<'_>) -> Self {
let mut root = Shared::null();
let bin = Shared::from(Box::into_raw(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 8ae16b5

Please sign in to comment.