-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Avoid stack -> Box
copy when data can be put in Box
directly
#101829
Comments
Triage: Can you explain a bit more what you want rustc to change here? If you have particular inlining needs, using #[inline(always)] does not seem unreasonable? |
@rustbot label A-box |
Triage: Thanks for adding the label, but at this point I think we can go ahead and close this as obsolete since the reporter did not get back with a clarification. |
Why close, is the codegen issue fixed? What the OP wants is to avoid the large copy to the stack to do a heap allocation. That being said, it’s surely far from the only open issue about this. |
I think there is an issue about that already which would make this a duplicate. I'll look for it later today. Thanks for clarifying. |
Im sure there are a ton, yes. |
Yep. |
Box
when it can be avoided
Box
when it can be avoidedBox
copy when data can be put in Box
directly
I only found #53827 which I don't think is a perfect duplicate. So I
Sorry for any inconvenience and thank you for the cooperation. Of course feel free to make whatever further adjustments you like. |
In https://bugzilla.mozilla.org/show_bug.cgi?id=1787715 (currently not public for security reasons) we ran into a stack overflow when flate2 calls
Box::<CompressorOxide>>::default()
inDeflateBackend::make()
here:https://github.com/rust-lang/flate2-rs/blob/cc5ed7f817cc5e5712b2bb924ed19cab4f389a47/src/ffi/rust.rs#L131
DeflateBackend::make()
is getting compiled with a call tochkstk(65664)
A reduced version of this is here:
https://rust.godbolt.org/z/hTE3785xY
A further reduced version that doesn't require any of the special
box
syntax inDefault()
is here:https://rust.godbolt.org/z/8e5EPafzb
This seems to have to do with
LZOxide::new()
not being inlined. If it's inlined the problem goes away. If the field initialization order ofCompressorOxide
is swappedso that we call
Box::<u32>::default()
beforeLZOxide::new()
the problem also goes away.@nikic
The text was updated successfully, but these errors were encountered: