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::worker
field is a*mut GCWorker<VM>
. This is unsafe.ProcessEdgesWork
needs to access the worker instance becauseXxxxxxSpace::trace_object
needs aGCWorker<VM>
reference to get theCopyContext
, andflush()
needs aGCWorker<VM>
to submit or executeScanObjects
work packets.Currently,
ProcessEdgesWork
attempts to give itself access toGCWorker
by holding a*mut GCWorker<VM>
in theProcessEdgesBase::worker
field. This is unsafe, because the work packet is not associated to aGCWorker
until it is executed by aGCWorker
. The access to the*mut GCWorker<VM>
pointer is invalid beforedo_work
starts, and afterdo_work
finishes.In idiomatic Rust, if the
GCWorker
is only valid to access during the execution ofgc_work
, it should be passed togc_work
as a&mut GCWorker<VM>
reference. Rust's borrowing semantics will ensure that it is only borrowed during the execution ofgc_work
.Actually
GCWork::do_work
already 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 GCWorker
parameter 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'w
and contains a&'w mut GCWorker
, and use that struct as theself
, but only during the execution ofdo_work
.