-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
fix numerous issues with WeakKeyDict #38180
Conversation
I like the general idea but there are still some issues. For example I was able to look up
|
Yeah, I'm not quite sure how to deal with that. I'm considering just defining |
Overall direction looks right to me. |
Delay cleanup of WeakKeyDict items until the next insertion. And fix `get!`, since previously usage of it would have added keys without finalizers to the dict. Fixes #26939
22d0ab8
to
68e5b47
Compare
It still seems worthwhile to me for length to call |
Delay cleanup of WeakKeyDict items until the next insertion. And fix `get!`, since previously usage of it would have added keys without finalizers to the dict. Fixes JuliaLang#26939
The underlying issues was addressed with the change in WeakRef semantics in JuliaLang#38180. However, we still want the test. Closes JuliaLang#38727
Thanks to #38180, the removed code seems to be dead because no finalizers should be used anymore to modify dictionaries (it was dangerous). Furthermore, it may help users to detect illegal concurrent writes, since it doesn't recurse and have new error message. There should be no, or even a positive, performance effect.
Delay cleanup of WeakKeyDict items until the next insertion. (And fix
get!
, since previously usage of it would have added keys withoutfinalizers to the dict.)
The most significant change here is that I'm changing the way WeakKey works: now instead of the GC clearing the internal reference after the last instance of it disappears from the system (after running finalizers), I'm instead clearing it prior to (happens-before) scheduling any finalization. This is significant because—while this breaks the old implementation of WeakKeyDict—it is a necessary property for precise detection of whether the object is still strongly alive after recovering a reference to it out of a WeakKey object. This happens to be how other languages do it (https://docs.oracle.com/javase/8/docs/api/java/lang/ref/WeakReference.html, https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/weak-references), so I feel reassured this is the right change.
This also means we could also now drop the internal
lock
that was need to make this thread-safe (not implemented yet). Thoughts?Fixes #26939