Commit 42b9a04
authored
Rollup merge of rust-lang#58431 - RalfJung:btree, r=Mark-Simulacrum
fix overlapping references in BTree
This fixes two kinds of overlapping references in BTree (both found by running the BTree test suite in Miri).
In `into_slices_mut`, we did `k.into_key_slice_mut()` followed by `self.into_val_slice_mut()` (where `k` is a copy of `self`). Calling `into_val_slice_mut` calls `self.len()`, which creates a shared reference to `NodeHeader`, which unfortunately (due to padding) overlaps with the mutable reference returned by `into_key_slice_mut`. Hence the key slice got (partially) invalidated. The fix is to avoid creating an `&NodeHeader` after the first slice got created.
In the iterators, we used to first create the references that will be returned, and then perform the walk on the tree. Walking the tree creates references (such as `&mut InternalNode`) that overlap with all of the keys and values stored in a pointer; in particular, they overlap with the references the iterator will later return. This is fixed by reordering the operations of walking the tree and obtaining the inner references.
The test suite still passes (and it passes in Miri now!), but there is a lot of code here that I do not understand...2 files changed
+42
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1634 | 1634 | | |
1635 | 1635 | | |
1636 | 1636 | | |
1637 | | - | |
1638 | | - | |
1639 | | - | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
1640 | 1642 | | |
1641 | 1643 | | |
1642 | 1644 | | |
| |||
1647 | 1649 | | |
1648 | 1650 | | |
1649 | 1651 | | |
1650 | | - | |
1651 | | - | |
1652 | | - | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
1653 | 1657 | | |
1654 | 1658 | | |
1655 | 1659 | | |
| |||
1680 | 1684 | | |
1681 | 1685 | | |
1682 | 1686 | | |
1683 | | - | |
1684 | | - | |
1685 | | - | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
1686 | 1692 | | |
1687 | 1693 | | |
1688 | 1694 | | |
| |||
1693 | 1699 | | |
1694 | 1700 | | |
1695 | 1701 | | |
1696 | | - | |
1697 | | - | |
1698 | | - | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
1699 | 1707 | | |
1700 | 1708 | | |
1701 | 1709 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
645 | 645 | | |
646 | 646 | | |
647 | 647 | | |
| 648 | + | |
| 649 | + | |
648 | 650 | | |
649 | 651 | | |
650 | 652 | | |
| |||
667 | 669 | | |
668 | 670 | | |
669 | 671 | | |
670 | | - | |
671 | | - | |
672 | | - | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
673 | 692 | | |
674 | 693 | | |
675 | 694 | | |
| |||
0 commit comments