-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
std: Fix Rc with Gc inside of it #11533
Conversation
The code in Rc assumes that the inner box is allocated on the global exchange heap, which is not always true. If T has managed pointers inside of it, it's allocate on the local heap instead. This commit reconciles these two modes of T by carefully interacting with the inner box (with special treatment of its deallocation). Closes rust-lang#11532
I already wrote the code to do this and you didn't want me to include in my pull request... There's no reason for unique pointers to ever be allocated with |
I do not remember you writing any code that looks like this. You had a new There may not be a reason to use There most certainly is a good reason to add this and it's memory safety! This is entirely memory unsafe if you're using a Gc in an Rc and attempting to get a reference to this. Our options are to add a Depending on how Gc is updated in the future, this will have to stay in sync, but that's the point of regression tests. |
@alexcrichton: I told you several times that I had added the necessary transmutes to support this. I also discovered some take glue issues along the way that are still present here but it's probably not specific to
It wouldn't be hard to remove the code paths I added in the pull request removing the headers from some but not all unique boxes. That's the correct fix here since there's no way these headers are actually going to be used by the garbage collector and it adds a lot of extra code to
Just remove the It's also memory-unsafe with the |
Can I submit a pull request removing unique pointer/vector headers completely? |
You're not discussing the issue at hand any more. You're describing problems with the rest of the compiler. Whether the headers are needed right now or not is irrelevant. I would personally be ok with removing headers, but you should talk to @pnkfelix first (and not in this bug). |
Will this break the bootstrap? (Since rustc is so |
@huonw: Nope, they're not used. I previously removed all of the headers and then added branches to put them back on managed-unique because Graydon's garbage collector required it. |
@alexcrichton: I don't think it's irrelevant, because it would make this unnecessary and fix the unique vector methods. I really don't think we should add more special cases like the ones in |
Again, you're not discussing the issue at hand, you continue to go on tangents. As far as I know, @pnkfelix is working on the new GC, so he'd know whether we want to keep these headers or not. Please continue this discussion with him. Yes, I agree that this patch doesn't matter if we don't have headers. No, we're not removing headers right now (pending talks with others). Please continue this discussion about removing headers in a different location (or make a PR to discuss on). |
It's not a tangent. There's no reason to add more special cases if we just remove the cause of these special cases. A workaround for an easily fixable issue that's going to just need to be removed too doesn't make sense to me. |
This is better than the current situation, but it seems potentially problematic to drop a box with a different size, since the allocator could very well rely on knowing the allocation size on both alloc and free (for instance, larger allocations could be performed by directly calling mmap and munmap, and the size must be passed to munmap and adding an header could waste a whole page). There is also another issue: tracing RcBox with an hypotetical tracing GC is currently broken, because the GC doesn't know whether the contents are alive or not and thus will either always or never trace them, which are both wrong. I think what ideally needs to be done is to have a "StrongBox" type that encapsulates the data and strong reference count, stores the data as an [u8, ..sizeof(T)] and manually implements tracing and dropping correctly, knowing that the data is only constructed if the reference count is != 0 (as well as providing try_borrow, try_add_ref, release, etc.) |
At this point, I'd rather punt on all "hypothetical GC concerns" because there are a lot of concerns. I agree that dropping something of a different type right is disturbing, but nearly everything in here is dependent on the implementation of the allocator anyway. Regardless, I'm gonna go ahead and close this in favor of #11535 (although I do like removing all of the unsafe blocks...) |
The GC tracing will be fixed by having a user implementable trait to control tracing, similar to Drop. |
Unique pointers and vectors currently contain a reference counting header when containing a managed pointer. This `{ ref_count, type_desc, prev, next }` header is not necessary and not a sensible foundation for tracing. It adds needless complexity to library code and is responsible for breakage in places where the branch has been left out. The `borrow_offset` field can now be removed from `TyDesc` along with the associated handling in the compiler. Closes #9510 Closes #11533
Unique pointers and vectors currently contain a reference counting header when containing a managed pointer. This `{ ref_count, type_desc, prev, next }` header is not necessary and not a sensible foundation for tracing. It adds needless complexity to library code and is responsible for breakage in places where the branch has been left out. The `borrow_offset` field can now be removed from `TyDesc` along with the associated handling in the compiler. Closes #9510 Closes #11533
Fix `is_from_proc_macro` patterns fixes rust-lang#11533 changelog: none
Fix `is_from_proc_macro` patterns fixes rust-lang#11533 changelog: none
Fix `is_from_proc_macro` patterns fixes rust-lang#11533 changelog: none
Fix `is_from_proc_macro` patterns fixes rust-lang#11533 changelog: none
Fix `is_from_proc_macro` patterns fixes rust-lang#11533 changelog: none
The code in Rc assumes that the inner box is allocated on the global exchange
heap, which is not always true. If T has managed pointers inside of it, it's
allocate on the local heap instead.
This commit reconciles these two modes of T by carefully interacting with the
inner box (with special treatment of its deallocation).
Closes #11532