Skip to content

MIR: Implement dynamic dropping scheme #29855

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

Closed
nagisa opened this issue Nov 16, 2015 · 9 comments
Closed

MIR: Implement dynamic dropping scheme #29855

nagisa opened this issue Nov 16, 2015 · 9 comments
Labels
A-destructors Area: Destructors (`Drop`, …) A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html

Comments

@nagisa
Copy link
Member

nagisa commented Nov 16, 2015

#[rustc_mir]
fn into_inner(x: Drp) {
    loop {
        let d = x;
        break;
    }
}

where impl Drop for Drp. The Drp destructor will be called 3 times.

@nagisa
Copy link
Member Author

nagisa commented Nov 16, 2015

Interestingly, noting seems to be ever stored into %d or %temp1.

; Function Attrs: uwtable
define internal void @_ZN10into_inner20h17287350f8168d4atbaE(i8) unnamed_addr #0 {
entry-block:
  %dropflag_hint_83 = alloca i8
  %dropflag_hint_91 = alloca i8
  %x = alloca %Drp
  %d = alloca %Drp
  %temp0 = alloca {}
  %temp1 = alloca %Drp
  %temp2 = alloca {}
  %arg0 = alloca %Drp
  store i8 61, i8* %dropflag_hint_83
  store i8 61, i8* %dropflag_hint_91
  %1 = bitcast %Drp* %arg0 to i8*
  store i8 %0, i8* %1, align 1
  br label %"BB(0)"

"BB(0)":                                          ; preds = %entry-block
  %2 = bitcast %Drp* %arg0 to i8*
  %3 = load i8, i8* %2, align 1
  %4 = bitcast %Drp* %x to i8*
  store i8 %3, i8* %4, align 1
  br label %"BB(3)"

"BB(1)":                                          ; preds = %"BB(4)"
  ret void

"BB(2)":                                          ; No predecessors!
  unreachable

"BB(3)":                                          ; preds = %"BB(0)"
  %5 = bitcast %Drp* %x to i8*
  %6 = load i8, i8* %5, align 1
  %7 = bitcast %Drp* %temp1 to i8*
  store i8 %6, i8* %7, align 1
  %8 = bitcast %Drp* %temp1 to i8*
  %9 = load i8, i8* %8, align 1
  %10 = bitcast %Drp* %d to i8*
  store i8 %9, i8* %10, align 1
  call void @_ZN3Drp9drop.332317hb0d710f73d73278eE(%Drp* %temp1)
  call void @_ZN3Drp9drop.332317hb0d710f73d73278eE(%Drp* %d)
  br label %"BB(4)"

"BB(4)":                                          ; preds = %"BB(3)"
  call void @_ZN3Drp9drop.332317hb0d710f73d73278eE(%Drp* %x)
  br label %"BB(1)"
}

@huonw huonw added A-destructors Area: Destructors (`Drop`, …) A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html labels Nov 16, 2015
@dotdash
Copy link
Contributor

dotdash commented Nov 16, 2015

There are stores to %d and %temp1 in BB(3). There are just bitcasts around them that might be confusing. The actual problem here ist that the move never marks the value as moved.

@nikomatsakis
Copy link
Contributor

The problem here is that we never implemented the "dynamic drop" code that I planned to implement, I think.

@nikomatsakis
Copy link
Contributor

In the short-term though we could probably institute a zeroing scheme.

@nagisa
Copy link
Member Author

nagisa commented Dec 15, 2015

Another interesting case:

// Droppable is *NOT* Copy-able
#[rustc_mir(graphviz="foo.gv")]
fn mir() {
    let d1 = Droppable;
    drop(d1);
}

drop-current

Note, how we create a temporary to pass into the drop and then still drop both the argument we pass in and the original value, which comes down to three drops of the same value.

@arielb1
Copy link
Contributor

arielb1 commented Dec 15, 2015

@nagisa

MIR is supposed to be implemented on top of some dynamic drop scheme (zeroing or stack flags) - drop should not affect values that have been moved or dropped.

@nagisa
Copy link
Member Author

nagisa commented Dec 15, 2015

@arielb1 ah, okay.

@nagisa nagisa changed the title MIR translates drops incorrectly MIR: Implement dynamic dropping scheme Jan 6, 2016
@pnkfelix
Copy link
Member

cc me

@arielb1
Copy link
Contributor

arielb1 commented Jun 7, 2016

This is done.

@arielb1 arielb1 closed this as completed Jun 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-destructors Area: Destructors (`Drop`, …) A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
Projects
None yet
Development

No branches or pull requests

6 participants