Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upConsider using as_unsafe_cell when tracing RefCell values during GC #4778
Comments
|
What if we manipulate some form of list of JS objects during the GC pass? We might end up accessing freed memory or something. |
|
Though the solution for that seems to lie in Mutex land. I guess any member that is a pointer of JS pointers should be designed carefully so that this doesn't happen. |
But it won't be, will it? |
|
Mmm, right, I forgot that the pointer for |
|
This is showing up as intermittent test failures. I'm inclined to proceed with this change.
|
|
My current understanding of this is that
Is this understanding approximately correct? |
|
Yes! Although the GC doesn't do a second mutable borrow right now, it just tries to immutably borrow the value again, which fails if there is an outstanding mutable borrow. This situation is safe because the code is running on the same thread, so there won't be any data race. |
We don't have any guarantees about when GCs will run, so it's entirely possible (even likely?) that we'll end up double-borrowing a RefCell by triggering a GC while there is a mutable borrow outstanding. I think it's safe to just use
as_unsafe_cellduring this, since it's a read-only operation.