Skip to main content

gc_lite/
xref.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2025-2026 John Ray <996351336@qq.com>
3
4use std::ptr::NonNull;
5
6use crate::{GcHead, GcHeap, GcPartitionId};
7
8impl GcHead {
9    /// Get cross scope reference
10    #[deprecated]
11    pub fn xref(&self) -> GcPartitionId {
12        let p = (self.partition >> 16) as u16;
13        GcPartitionId(p)
14    }
15
16    /// Set cross scope reference.
17    ///
18    /// # Return
19    ///
20    /// * true if node has xref set
21    /// * false if node has xref unset
22    #[deprecated]
23    pub(crate) fn set_xref(&mut self, xref: GcPartitionId) -> bool {
24        if !xref.is_null() && xref != self.partition_id() {
25            log::trace!("[set_xref] {xref:?} -> {self:?}");
26            self.partition = (self.partition & 0x0000_FFFF) | ((xref.0 as u32) << 16);
27            true
28        } else {
29            self.partition &= 0x0000_FFFF;
30            false
31        }
32    }
33
34    /// Unset cross scope reference
35    #[deprecated]
36    #[inline(always)]
37    pub fn unset_xref(&mut self) {
38        self.set_xref(GcPartitionId::NONE);
39    }
40}
41
42impl GcHeap {
43    #[deprecated]
44    pub const fn set_xref(&mut self, from_scope: GcPartitionId, node: NonNull<GcHead>) -> bool {
45        false
46    }
47}