Remove ProcessEdgesBase::worker #597
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
ProcessEdgesBase::workerfield is a*mut GCWorker<VM>. This is unsafe.ProcessEdgesWorkneeds to access the worker instance becauseXxxxxxSpace::trace_objectneeds aGCWorker<VM>reference to get theCopyContext, andflush()needs aGCWorker<VM>to submit or executeScanObjectswork packets.Currently,
ProcessEdgesWorkattempts to give itself access toGCWorkerby holding a*mut GCWorker<VM>in theProcessEdgesBase::workerfield. This is unsafe, because the work packet is not associated to aGCWorkeruntil it is executed by aGCWorker. The access to the*mut GCWorker<VM>pointer is invalid beforedo_workstarts, and afterdo_workfinishes.In idiomatic Rust, if the
GCWorkeris only valid to access during the execution ofgc_work, it should be passed togc_workas a&mut GCWorker<VM>reference. Rust's borrowing semantics will ensure that it is only borrowed during the execution ofgc_work.Actually
GCWork::do_workalready has aworker: &mut GCWorker<VM>parameter. So we can pass it through levels of function calls to give them access toGCWorker.This PR attempts to do this.
DRAFT: I added
&mut GCWorkerparameter to too many functions, but only a few functions actually use it. This may indicate that there is still some room for refactoring. One possibility is to introduce a struct that has a lifetime parameter'wand contains a&'w mut GCWorker, and use that struct as theself, but only during the execution ofdo_work.