Skip to content
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

Collect trait breaking changes #107

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

moulins
Copy link
Collaborator

@moulins moulins commented Jul 18, 2024

Implements (mostly) the changes discussed in #105 (comment).
A small difference: I ditched the CollectFlags abstraction in favor of keeping a simple boolean; this makes the trait slightly less cumbersome to implement.

This also refactors Context to drastically reduce the need for RefCell locking, by borrowing the gray queues mutably during marking and tracing.

@moulins moulins force-pushed the collect-breaking-changes branch 4 times, most recently from 5c83d1c to 53371b7 Compare July 18, 2024 14:00
- Don't require `T: Sized` for `GcWeak::{from_ptr, cast}`
- Add `GcWeak::erase`
This gives a less footgunny way to trace `Gc<T>` pointers manually
without accidentally dereferencing them and using `T`'s `Collect`
impl instead (which is unsound!).
The following breaking changes are made:
- Replaced `needs_trace()` by an associated constant `NEEDS_TRACE`.
- The `Collection` type now takes a lifetime, and `Collect::trace` now
  takes a `Collection<'_>` instead of a `&Collection>`.
- Added methods on `Collection<'_>` to trace values.
- `Collect` is no longer object-safe.

These changes allow the following optimizations:
- Properly propagating `NEEDS_TRACE` in unsized types `RefLock<T>`
  and `[T]`.
- Early bailout in `Collection::trace` if the value doesn't need to be
  traced, avoiding reliance on the optimizer to remove empty loops etc.
…cking

To make this possible, moves the gray queues into a separate `MarkState`
struct; also clean-up the big `do_collection_inner` loop by moving mark
& sweep logic into their separate methods.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant