-
Notifications
You must be signed in to change notification settings - Fork 129
Added traceable for std::rc::Weak #659
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
Open
Narfinger
wants to merge
1
commit into
servo:main
Choose a base branch
from
Narfinger:traceable_for_weak
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that I understand the motivation. Upgraded weak that is held across GC should prevent drop of inner, at least until the the drop of upgrade (which happens after GC is done). Also if we would do this weakref somehow losses the point of being weakref.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it is something that I missunderstood how the Gc works but here is the scenario without this.
Let us have a struct
Foo, andRc<Foo>inStruct2and aWeak<Foo>.Weak<Foo>is annotated with #[no_trace] because the developer believes that the Gc can always trace Foo via the Rc.Now somewhere in the code we call
let bar = Weak<Foo>::upgrade(), giving us theRc<Foo>on the stack. While we are doing something withbarthe structStruct2goes out of scope, makingFooonly be reachable bybar.baris, however, not traced by the Gc, so it can be cleaned up in the next garbage collection.I am not sure if weakref is the same or a different thing. The documentation is not really clear to me.
I am new to Gc stuff, so this might already be covered by something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the worst case we can even imagine that someone just ran
mem::forgeton a strong ref. So I think we definitely need to treat these the same way as strong refs.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case you should root the upgrade (this should be enforced by crown as no unrooted stuff should be allowed on the stack). Something similar is done by weakref, where weakref itself is not traced (it actually implements nop trace), but when you upgrading you get the rooted inner.
With that being said, in servo we occasionally use the fact that when the method on dom_struct is called, whole doe_struct is rooted, so one does not need to root it's fields (Dom) as they are rooted from the dom_struct (for the lifetime of dom_struct - &self), but one returning values (refs) to those fields one needs to root them. Is that motivation for this, or you have any other concrete case in servo to consider here?
This causes a memory leak (even if temporary) and we do not want those in servo. Although that might not seem that problematic at first as at least one of uses must be rooted; I think it actually is as most weak uses are in globalscope which is basically perma-rooted (for the time of lifetime of the page). I know we had problems with such leaks before, but do not have link on hand.