-
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
Optimize Box::default
and Arc::default
to construct more types in place
#131460
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why only do this for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jwong101 Can you make a follow-up PR to do the same thing for |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//@ compile-flags: -O | ||
#![crate_type = "lib"] | ||
|
||
// Test to check that types with "complex" destructors, but trivial `Default` impls | ||
// are constructed directly into the allocation in `Box::default` and `Arc::default`. | ||
|
||
use std::sync::Arc; | ||
|
||
// CHECK-LABEL: @box_default_inplace | ||
#[no_mangle] | ||
pub fn box_default_inplace() -> Box<(String, String)> { | ||
// CHECK-NOT: alloca | ||
// CHECK: [[BOX:%.*]] = {{.*}}call {{.*}}__rust_alloc( | ||
// CHECK-NOT: call void @llvm.memcpy | ||
// CHECK: ret ptr [[BOX]] | ||
Box::default() | ||
} | ||
|
||
// CHECK-LABEL: @arc_default_inplace | ||
#[no_mangle] | ||
pub fn arc_default_inplace() -> Arc<(String, String)> { | ||
// CHECK-NOT: alloca | ||
// CHECK: [[ARC:%.*]] = {{.*}}call {{.*}}__rust_alloc( | ||
// CHECK-NOT: call void @llvm.memcpy | ||
// CHECK: ret ptr [[ARC]] | ||
Arc::default() | ||
} |
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.
gotta say, love to see that this is still entirely safe code thanks to
MaybeUninit
and existing APIs 🎉