-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Stop clearing box's drop flags early #131146
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
Open
beepster4096
wants to merge
2
commits into
rust-lang:master
Choose a base branch
from
beepster4096:box_drop_flags
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+268
−13
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
tests/mir-opt/box_conditional_drop_allocator.main.ElaborateDrops.diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
- // MIR for `main` before ElaborateDrops | ||
+ // MIR for `main` after ElaborateDrops | ||
|
||
fn main() -> () { | ||
let mut _0: (); | ||
let _1: std::boxed::Box<HasDrop, DropAllocator>; | ||
let mut _2: HasDrop; | ||
let mut _3: DropAllocator; | ||
let mut _4: bool; | ||
let _5: (); | ||
let mut _6: HasDrop; | ||
let _7: (); | ||
let mut _8: std::boxed::Box<HasDrop, DropAllocator>; | ||
+ let mut _9: bool; | ||
+ let mut _10: &mut std::boxed::Box<HasDrop, DropAllocator>; | ||
+ let mut _11: (); | ||
+ let mut _12: &mut std::boxed::Box<HasDrop, DropAllocator>; | ||
+ let mut _13: (); | ||
+ let mut _14: &mut std::boxed::Box<HasDrop, DropAllocator>; | ||
+ let mut _15: (); | ||
scope 1 { | ||
debug b => _1; | ||
} | ||
|
||
bb0: { | ||
+ _9 = const false; | ||
StorageLive(_1); | ||
StorageLive(_2); | ||
_2 = HasDrop; | ||
StorageLive(_3); | ||
_3 = DropAllocator; | ||
_1 = Box::<HasDrop, DropAllocator>::new_in(move _2, move _3) -> [return: bb1, unwind: bb11]; | ||
} | ||
|
||
bb1: { | ||
+ _9 = const true; | ||
StorageDead(_3); | ||
StorageDead(_2); | ||
StorageLive(_4); | ||
_4 = const true; | ||
switchInt(move _4) -> [0: bb4, otherwise: bb2]; | ||
} | ||
|
||
bb2: { | ||
StorageLive(_5); | ||
StorageLive(_6); | ||
_6 = move (*_1); | ||
_5 = std::mem::drop::<HasDrop>(move _6) -> [return: bb3, unwind: bb9]; | ||
} | ||
|
||
bb3: { | ||
StorageDead(_6); | ||
StorageDead(_5); | ||
_0 = const (); | ||
goto -> bb6; | ||
} | ||
|
||
bb4: { | ||
StorageLive(_7); | ||
StorageLive(_8); | ||
+ _9 = const false; | ||
_8 = move _1; | ||
_7 = std::mem::drop::<Box<HasDrop, DropAllocator>>(move _8) -> [return: bb5, unwind: bb8]; | ||
} | ||
|
||
bb5: { | ||
StorageDead(_8); | ||
StorageDead(_7); | ||
_0 = const (); | ||
goto -> bb6; | ||
} | ||
|
||
bb6: { | ||
StorageDead(_4); | ||
- drop(_1) -> [return: bb7, unwind continue]; | ||
+ goto -> bb22; | ||
} | ||
|
||
bb7: { | ||
+ _9 = const false; | ||
StorageDead(_1); | ||
return; | ||
} | ||
|
||
bb8 (cleanup): { | ||
- drop(_8) -> [return: bb10, unwind terminate(cleanup)]; | ||
+ goto -> bb10; | ||
} | ||
|
||
bb9 (cleanup): { | ||
- drop(_6) -> [return: bb10, unwind terminate(cleanup)]; | ||
+ goto -> bb10; | ||
} | ||
|
||
bb10 (cleanup): { | ||
- drop(_1) -> [return: bb13, unwind terminate(cleanup)]; | ||
+ goto -> bb27; | ||
} | ||
|
||
bb11 (cleanup): { | ||
- drop(_3) -> [return: bb12, unwind terminate(cleanup)]; | ||
+ goto -> bb12; | ||
} | ||
|
||
bb12 (cleanup): { | ||
- drop(_2) -> [return: bb13, unwind terminate(cleanup)]; | ||
+ goto -> bb13; | ||
} | ||
|
||
bb13 (cleanup): { | ||
resume; | ||
+ } | ||
+ | ||
+ bb14: { | ||
+ _9 = const false; | ||
+ goto -> bb7; | ||
+ } | ||
+ | ||
+ bb15 (cleanup): { | ||
+ drop((_1.1: DropAllocator)) -> [return: bb13, unwind terminate(cleanup)]; | ||
+ } | ||
+ | ||
+ bb16 (cleanup): { | ||
+ switchInt(copy _9) -> [0: bb13, otherwise: bb15]; | ||
+ } | ||
+ | ||
+ bb17: { | ||
+ drop((_1.1: DropAllocator)) -> [return: bb14, unwind: bb13]; | ||
+ } | ||
+ | ||
+ bb18: { | ||
+ switchInt(copy _9) -> [0: bb14, otherwise: bb17]; | ||
+ } | ||
+ | ||
+ bb19: { | ||
+ _10 = &mut _1; | ||
+ _11 = <Box<HasDrop, DropAllocator> as Drop>::drop(move _10) -> [return: bb18, unwind: bb16]; | ||
+ } | ||
+ | ||
+ bb20 (cleanup): { | ||
+ _12 = &mut _1; | ||
+ _13 = <Box<HasDrop, DropAllocator> as Drop>::drop(move _12) -> [return: bb16, unwind terminate(cleanup)]; | ||
+ } | ||
+ | ||
+ bb21: { | ||
+ goto -> bb19; | ||
+ } | ||
+ | ||
+ bb22: { | ||
+ switchInt(copy _9) -> [0: bb7, otherwise: bb21]; | ||
+ } | ||
+ | ||
+ bb23 (cleanup): { | ||
+ drop((_1.1: DropAllocator)) -> [return: bb13, unwind terminate(cleanup)]; | ||
+ } | ||
+ | ||
+ bb24 (cleanup): { | ||
+ switchInt(copy _9) -> [0: bb13, otherwise: bb23]; | ||
+ } | ||
+ | ||
+ bb25 (cleanup): { | ||
+ _14 = &mut _1; | ||
+ _15 = <Box<HasDrop, DropAllocator> as Drop>::drop(move _14) -> [return: bb24, unwind terminate(cleanup)]; | ||
+ } | ||
+ | ||
+ bb26 (cleanup): { | ||
+ goto -> bb25; | ||
+ } | ||
+ | ||
+ bb27 (cleanup): { | ||
+ switchInt(copy _9) -> [0: bb13, otherwise: bb26]; | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// skip-filecheck | ||
//@ test-mir-pass: ElaborateDrops | ||
#![feature(allocator_api)] | ||
|
||
// Regression test for #131082. | ||
// Testing that the allocator of a Box is dropped in conditional drops | ||
|
||
use std::alloc::{AllocError, Allocator, Global, Layout}; | ||
use std::ptr::NonNull; | ||
|
||
struct DropAllocator; | ||
|
||
unsafe impl Allocator for DropAllocator { | ||
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> { | ||
Global.allocate(layout) | ||
} | ||
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | ||
Global.deallocate(ptr, layout); | ||
} | ||
} | ||
impl Drop for DropAllocator { | ||
fn drop(&mut self) {} | ||
wesleywiser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
struct HasDrop; | ||
impl Drop for HasDrop { | ||
fn drop(&mut self) {} | ||
wesleywiser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// EMIT_MIR box_conditional_drop_allocator.main.ElaborateDrops.diff | ||
fn main() { | ||
let b = Box::new_in(HasDrop, DropAllocator); | ||
if true { | ||
drop(*b); | ||
} else { | ||
drop(b); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//@ run-pass | ||
#![feature(allocator_api)] | ||
|
||
// Regression test for #131082. | ||
// Testing that the allocator of a Box is dropped in conditional drops | ||
|
||
use std::alloc::{AllocError, Allocator, Global, Layout}; | ||
use std::cell::Cell; | ||
use std::ptr::NonNull; | ||
|
||
struct DropCheckingAllocator<'a>(&'a Cell<bool>); | ||
|
||
unsafe impl Allocator for DropCheckingAllocator<'_> { | ||
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> { | ||
Global.allocate(layout) | ||
} | ||
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | ||
Global.deallocate(ptr, layout); | ||
} | ||
} | ||
impl Drop for DropCheckingAllocator<'_> { | ||
fn drop(&mut self) { | ||
self.0.set(true); | ||
} | ||
} | ||
|
||
struct HasDrop; | ||
impl Drop for HasDrop { | ||
fn drop(&mut self) {} | ||
} | ||
|
||
fn main() { | ||
let dropped = Cell::new(false); | ||
{ | ||
let b = Box::new_in(HasDrop, DropCheckingAllocator(&dropped)); | ||
if true { | ||
drop(*b); | ||
} else { | ||
drop(b); | ||
} | ||
} | ||
assert!(dropped.get()); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.