Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add ?Sized bounds to all (?) appropriate locations I have added ?Sized to pretty much all T that is garbage collected and that needs it. However, there are a few structs defined in a rental! macro that are causing the build to break due to trasmutation rules. Enforcing a Sized bound causes the GcRef type to require a Sized T, which doesn't seem right. * Removed ?Sized bounds from smart-pointer implementations of RwLock, Mutex, and RefCell The implementations of RwLock, Mutex, and RefCell all have special guards for their borrow() (and related) functions that wrap around their normal standard library guards. These guards are implemented using the rental crate, which has a special macro that does some magic behind the scenes involving transmutation of types - which breaks some type rules when they're possibly unsized. This now compiles, and the Gc<RwLock>, Gc<Mutex>, and Gc<RefCell> types do not have access to the ergonomic GcRef type or their special borrow() family of methods. * WIP: add nightly-only features CoerceUnsized and Unsize These allow a `Gc<T>` to be coerced to a `Gc<dyn R>` when `T` is some trait `R`. This requires `std::ops::CoerceUnsized` and `std::marker::Unsize`, which are nightly features. TODO: Add compile-time bounds for these functions/imports * Add support for converting Box<T> to a Gc<T> where T: ?Size Unsized types are able to be created by allocating a Box<T>, converting it to a Box<dyn MyTrait>, and then moving that pointer to the allocator. * Add `ToScan` trait which forces the value to be converted to a `&dyn Scan`, which is required for using any of the new `from_box` methods. Also add `impl_to_scan_safe` macro for convenience * Add Gc::from_box function for converting the boxed value to a GC'd value * Add GcAllocation::from_box function which does the actual convertion from the boxed value to a pointer * Add Colletor::track_boxed_value which tracks a pointer as if it is a raw pointer from a `Box<T>` * Add DeallocationAction::BoxDrop, which tells the collector tracking to convert the associated pointer back to the appropriate `Box<T>` before dropping it * Add guards to nightly features CoerceUnsized and Unsize are both nightly features. These are now guarded at compile time so the library will compile on stable Rust again. * Run cargo fmt * Remove impl_to_scan_safe macro in favor of blanket impl * Alphabetize new member in DeallocateAction with respect to other members * Add newline for style Signed-off-by: Alek Ratzloff <alekratz@gmail.com> * Add exception for calling dealloc() in GcAllocation::deallocate() Since types that are adapted from a boxed pointer are already dropped by the time dealloc() is called, this would result in a double-free which is !!!UNSAFE!!! and an obvious bug. Now, the deallocation action is checked before attempting to call dealloc() on a pointer. * Add "nightly-features" feature, to enable nightly features It appears my use of `#[cfg(nightly)]` was futile, since that's not an actual flag that the compiler uses with nightly code. Basically, users have to opt-in to nightly features themselves. Now that this has been fixed, a couple of compile-time errors popped up that are fixed as well. * Add ?Sized constraint for T on impl CoerceUnsized for Gc<T> This was preventing basic operation (i.e. transitivity was not being upheld). Weird errors for sure. * Add small integration test for coercion of unsized types This doesn't really test anything extensive, it mostly demonstrates how unsized types may be used with linked lists. * Remove useless test mutex from coercion test There is only one test in this file, so there are no race conditions to guard against. * Add test for unsized (immutable) types This test ensures that some `T` that is `SomeTrait: Scan + ToScan` can be put behind a `Gc<dyn SomeTrait>` pointer and shared that way. This tests `Gc::from_box`, which is the primary way to access this behavior. * Add make_node! macro to unsized type test * Run rustfmt
- Loading branch information