minirust icon indicating copy to clipboard operation
minirust copied to clipboard

minimize: Add support for `Box`

Open bifbof opened this issue 8 months ago • 3 comments

Currently the following code cannot be translated

fn main() {
    let _ = Box::new(42);
}

Currently we can reach 3 different error states (due to nondeterminism in translation) if we try to minimize this.

  • [ ] missing ShallowInitBox rvalue
  • [ ] missing NullaryOp rvalue (part of #201)
  • [x] missing resume terminator

First:

error: internal compiler error: minimize/src/rvalue.rs:234:18: rvalue failed to translate: ShallowInitBox(Move(_4), Ty { id: 1, kind: RigidTy(Int(I32)) })
   --> /home/bifbof/.rustup/toolchains/nightly-2024-05-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:218:9
    |
218 |         Box::new(x)
    |         ^^^^^^^^^^^

thread 'rustc' panicked at minimize/src/rvalue.rs:234:18:
Box<dyn Any>
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: aborting due to 1 previous error

Second:

error: internal compiler error: minimize/src/rvalue.rs:234:18: rvalue failed to translate: NullaryOp(SizeOf, Ty { id: 1, kind: RigidTy(Int(I32)) })
   --> /home/bifbof/.rustup/toolchains/nightly-2024-05-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:218:9
    |
218 |         Box::new(x)
    |         ^^^^^^^^^^^

thread 'rustc' panicked at minimize/src/rvalue.rs:234:18:
Box<dyn Any>
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: aborting due to 1 previous error

Third:

error: internal compiler error: minimize/src/bb.rs:163:18: terminator not supported: resume
   --> /home/bifbof/.rustup/toolchains/nightly-2024-05-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:216:5
    |
216 | /     pub fn new(x: T) -> Self {
217 | |         #[rustc_box]
218 | |         Box::new(x)
219 | |     }
    | |_____^

thread 'rustc' panicked at minimize/src/bb.rs:163:18:
Box<dyn Any>
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: aborting due to 1 previous error

bifbof avatar Jun 21 '24 19:06 bifbof