Skip to content

Commit 7c7e790

Browse files
committed
Revert "[simple] Use bit-magic to implement RawMarkState::resolve"
This doesn't actually work :( This reverts commit 161f5d0.
1 parent 3e026b3 commit 7c7e790

File tree

1 file changed

+18
-48
lines changed

1 file changed

+18
-48
lines changed

libs/simple/src/lib.rs

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -881,45 +881,27 @@ enum RawMarkState {
881881
/// Normally this marks the white state
882882
///
883883
/// If we're inverted, this marks black
884-
Red = 0,
884+
Red,
885885
/// This always marks the grey state
886886
///
887887
/// Inverting the mark bit doesn't affect the
888888
/// grey state
889-
Grey = 3,
889+
Grey,
890890
/// Normally this marks the blue state
891891
///
892892
/// If we're inverted, this marks white
893-
Blue = 1
893+
Blue
894894
}
895895
impl RawMarkState {
896896
#[inline]
897897
fn resolve(self, inverted_mark: bool) -> MarkState {
898-
let expected: MarkState;
899-
#[cfg(debug_assertions)] {
900-
expected = match (self, inverted_mark) {
901-
(RawMarkState::Red, false) => MarkState::White,
902-
(RawMarkState::Red, true) => MarkState::Black,
903-
(RawMarkState::Grey, _) => MarkState::Grey,
904-
(RawMarkState::Blue, false) => MarkState::Black,
905-
(RawMarkState::Blue, true) => MarkState::White
906-
};
907-
}
908-
/*
909-
* Bit magic works as expected (both ways):
910-
* (self as u8) ^ (inverted_mark as u8) => (res_bits as MarkState)
911-
* (Red => 0u8) ^ (false as 0u8) => (0u8 as White)
912-
* (Red => 0u8) ^ (true as 1u8) => (1u8 as Black)
913-
* (Grey => 3u8) ^ (false as 0u8) => (3u8 as Grey)
914-
* (Grey => 3u8) ^ (true as 1u8) => (3u8 as Grey)
915-
* (Blue => 1u8) ^ (false as 0u8) => (1u8 as Black)
916-
* (Blue => 1u8) ^ (true as 1u8) => (0u8 as White)
917-
*/
918-
let bits = (self as u8) ^ (inverted_mark as u8);
919-
#[cfg(debug_assertions)] {
920-
debug_assert_eq!(expected as u8, bits);
898+
match (self, inverted_mark) {
899+
(RawMarkState::Red, false) => MarkState::White,
900+
(RawMarkState::Red, true) => MarkState::Black,
901+
(RawMarkState::Grey, _) => MarkState::Grey,
902+
(RawMarkState::Blue, false) => MarkState::Black,
903+
(RawMarkState::Blue, true) => MarkState::White
921904
}
922-
unsafe { std::mem::transmute::<u8, MarkState>(bits) }
923905
}
924906
}
925907

@@ -933,37 +915,25 @@ enum MarkState {
933915
///
934916
/// Once all the objects have been marked,
935917
/// all remaining white objects will be freed.
936-
White = 0,
918+
White,
937919
/// The object is in the gray set and needs to be traversed to look for reachable memory
938920
///
939921
/// After being scanned this object will end up in the black set.
940-
Grey = 3,
922+
Grey,
941923
/// The object is in the black set and is reachable from the roots.
942924
///
943925
/// This object cannot be freed.
944-
Black = 1
926+
Black
945927
}
946928
impl MarkState {
947929
#[inline]
948930
fn to_raw(self, inverted_mark: bool) -> RawMarkState {
949-
let expected: RawMarkState;
950-
#[cfg(debug_assertions)] {
951-
expected = match (self, inverted_mark) {
952-
(MarkState::White, false) => RawMarkState::Red,
953-
(MarkState::White, true) => RawMarkState::Blue,
954-
(MarkState::Grey, _) => RawMarkState::Grey,
955-
(MarkState::Black, false) => RawMarkState::Blue,
956-
(MarkState::Black, true) => RawMarkState::Red,
957-
};
958-
}
959-
/*
960-
* Bit magic is reverse of `RawMarkState::resolved`
961-
* The justification there works two ways
962-
*/
963-
let bits = (self as u8) ^ (inverted_mark as u8);
964-
#[cfg(debug_assertions)] {
965-
debug_assert_eq!(expected as u8, bits);
931+
match (self, inverted_mark) {
932+
(MarkState::White, false) => RawMarkState::Red,
933+
(MarkState::White, true) => RawMarkState::Blue,
934+
(MarkState::Grey, _) => RawMarkState::Grey,
935+
(MarkState::Black, false) => RawMarkState::Blue,
936+
(MarkState::Black, true) => RawMarkState::Red,
966937
}
967-
unsafe { std::mem::transmute::<u8, RawMarkState>(bits) }
968938
}
969939
}

0 commit comments

Comments
 (0)