-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Have arrays' drop_glue just unsize and call the slice version
#155184
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| //@ revisions: RAW OPT | ||
| //@ compile-flags: -C opt-level=z -C panic=abort | ||
| //@[RAW] compile-flags: -C no-prepopulate-passes -Z inline-mir | ||
|
|
||
| #![crate_type = "lib"] | ||
|
|
||
| // Ensure all the different array drop_glue functions just delegate to the slice one, | ||
| // rather than emitting two loops in each of the three. | ||
|
|
||
| // When this test was first written, the array drop glues came out in the | ||
| // seemingly-arbitrary order of 42, then 7, then 13, so to avoid potential | ||
| // fragility from that changing we don't check any particular order. | ||
|
|
||
| // RAW: ; core::ptr::drop_glue::<[array_drop_glue::NeedsDrop; [[N:7|13|42]]]> | ||
| // RAW-NEXT: inlinehint | ||
| // RAW: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop]> | ||
|
Member
Author
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. Compare nightly https://rust.godbolt.org/z/5Wv1q86ja with a loop in each of the three. |
||
| // RAW-NEXT: noundef [[N]]) | ||
| // RAW: } | ||
|
|
||
| // RAW: ; core::ptr::drop_glue::<[array_drop_glue::NeedsDrop; [[N:7|13|42]]]> | ||
| // RAW-NEXT: inlinehint | ||
| // RAW: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop]> | ||
| // RAW-NEXT: noundef [[N]]) | ||
| // RAW: } | ||
|
|
||
| // RAW: ; core::ptr::drop_glue::<[array_drop_glue::NeedsDrop; [[N:7|13|42]]]> | ||
| // RAW-NEXT: inlinehint | ||
| // RAW: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop]> | ||
| // RAW-NEXT: noundef [[N]]) | ||
| // RAW: } | ||
|
|
||
| // CHECK-LABEL: ; core::ptr::drop_glue::<[array_drop_glue::NeedsDrop]> | ||
| // CHECK-NOT: inlinehint | ||
| // OPT: add nuw nsw {{.+}} 1 | ||
|
Member
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. What is this checking for?
Member
Author
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. That it's the actual loop which got optimized to |
||
| // CHECK: } | ||
|
|
||
| #[no_mangle] | ||
| // CHECK-LABEL: @drop_arrays | ||
| pub fn drop_arrays(x: [NeedsDrop; 7], y: [NeedsDrop; 13], z: [NeedsDrop; 42]) { | ||
| // I don't remember the parameter drop order, so write out the order the test expects. | ||
|
|
||
| // RAW: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop; 7]> | ||
| // OPT: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop]> | ||
| // OPT-NEXT: noundef 7) | ||
| drop(x); | ||
| // RAW: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop; 13]> | ||
| // OPT: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop]> | ||
| // OPT-NEXT: noundef 13) | ||
| drop(y); | ||
| // RAW: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop; 42]> | ||
| // OPT: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop]> | ||
| // OPT-NEXT: noundef 42) | ||
| drop(z); | ||
| } | ||
|
|
||
| struct NeedsDrop(u32); | ||
|
|
||
| impl Drop for NeedsDrop { | ||
| #[inline] | ||
| fn drop(&mut self) { | ||
| do_the_drop(self); | ||
| } | ||
| } | ||
|
|
||
| unsafe extern "Rust" { | ||
| safe fn do_the_drop(_: &mut NeedsDrop); | ||
| } | ||
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.
(question) What's the
def_ida def id of?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.
It's the def id of the
drop_glueitself. Basically the same asrequire_lang_item(LangItem::DropGlue), but it was already passed in to generate the drop glue we're currently making, so I didn't need to look it up -- the existing parameter on https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_transform/shim/fn.build_drop_shim.html.