-
Notifications
You must be signed in to change notification settings - Fork 477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interest in Gc'ing non-Boxed types? #379
Comments
Sorry for my lack of knowledge.. but I couldn't find good documentation of |
No worries! AFAIK there is no good documentation of the current version of /// Compiler-internal trait used to determine whether a type contains
/// any `UnsafeCell` internally, but not through an indirection.
/// This affects, for example, whether a `static` of that type is
/// placed in read-only static memory or writable static memory.
#[lang = "freeze"]
pub(crate) unsafe auto trait Freeze {}
impl<T: ?Sized> !Freeze for UnsafeCell<T> {}
unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
unsafe impl<T: ?Sized> Freeze for *const T {}
unsafe impl<T: ?Sized> Freeze for *mut T {}
unsafe impl<T: ?Sized> Freeze for &T {}
unsafe impl<T: ?Sized> Freeze for &mut T {}
Example usage: let s = Inline::new("hello".to_owned());
let guard = &epoch::pin();
let hello = s.load(guard);
s.store(" world!".to_owned(), guard);
let hello_world = hello.clone() + &*s.load(guard);
assert_eq!(hello_world, "hello world!"); Hope that helps! My intention wasn't to make a PR, but to see if there was any interest in it. I would want to make an RFC first, and also make an attempt at a rust-lang RFC to stabilize |
It seems I like this idea :) One thing I'm wondering is whether we can merge |
From what I read (not too familiar with D), references to
Not
I'm planning on an RFC to make |
If
std::marker::Freeze
was stabilized, crossbeam could have aAtomicCell
-like type whereload
works with non-Copy
data structures. Is this something crossbeam would be interested in? I've called itInline
in the examples below.It roughly works as follows:
load
requiresFreeze
instead ofCopy
. It takes in aGuard
, and performs a read (in the same memcpy style asAtomicCell
), but returns aSnapshot<'g, T>
which holds on to the lifetime of both the cell and the guard, provides only immutable access, and does notdrop
the value read.store
requiresFreeze
andSend
. It takes in aGuard
. If the type does not need dropping, then it behaves just asAtomicCell
. If it does need dropping, then it instead performs an atomicswap
(a laAtomicCell
), and then defers the drop of the old value:guard.defer(move || drop(old))
.Types like
String
/Vec<T>
/etc. could now be gc'ed without having to beBox
ed first.I have an implementation here which is largely copy-paste from
AtomicCell
.The text was updated successfully, but these errors were encountered: