Skip to content

Commit

Permalink
Use newly exposed Freeze trait.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Apr 7, 2024
1 parent 3b63e9d commit 8ce8fbf
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
- // MIR for `borrowed` before CopyProp
+ // MIR for `borrowed` after CopyProp

fn borrowed(_1: u32) -> bool {
fn borrowed(_1: T) -> bool {
let mut _0: bool;
let mut _2: u32;
let mut _3: &u32;
let mut _2: T;
let mut _3: &T;

bb0: {
- _2 = _1;
_3 = &_1;
_0 = opaque::<&u32>(_3) -> [return: bb1, unwind unreachable];
_0 = opaque::<&T>(_3) -> [return: bb1, unwind unreachable];
}

bb1: {
- _0 = opaque::<u32>(_2) -> [return: bb2, unwind unreachable];
+ _0 = opaque::<u32>(_1) -> [return: bb2, unwind unreachable];
- _0 = opaque::<T>(_2) -> [return: bb2, unwind unreachable];
+ _0 = opaque::<T>(_1) -> [return: bb2, unwind unreachable];
}

bb2: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
- // MIR for `borrowed` before CopyProp
+ // MIR for `borrowed` after CopyProp

fn borrowed(_1: u32) -> bool {
fn borrowed(_1: T) -> bool {
let mut _0: bool;
let mut _2: u32;
let mut _3: &u32;
let mut _2: T;
let mut _3: &T;

bb0: {
- _2 = _1;
_3 = &_1;
_0 = opaque::<&u32>(_3) -> [return: bb1, unwind continue];
_0 = opaque::<&T>(_3) -> [return: bb1, unwind continue];
}

bb1: {
- _0 = opaque::<u32>(_2) -> [return: bb2, unwind continue];
+ _0 = opaque::<u32>(_1) -> [return: bb2, unwind continue];
- _0 = opaque::<T>(_2) -> [return: bb2, unwind continue];
+ _0 = opaque::<T>(_1) -> [return: bb2, unwind continue];
}

bb2: {
Expand Down
10 changes: 6 additions & 4 deletions tests/mir-opt/copy-prop/borrowed_local.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ unit-test: CopyProp

#![feature(custom_mir, core_intrinsics)]
#![feature(custom_mir, core_intrinsics, freeze)]
#![allow(unused_assignments)]
extern crate core;
use core::marker::Freeze;
use core::intrinsics::mir::*;

fn opaque(_: impl Sized) -> bool { true }
Expand Down Expand Up @@ -42,14 +43,15 @@ fn compare_address() -> bool {
)
}

/// Generic type `T` is `Freeze`, so shared borrows are immutable.
#[custom_mir(dialect = "analysis", phase = "post-cleanup")]
fn borrowed(x: u32) -> bool {
fn borrowed<T: Copy + Freeze>(x: T) -> bool {
// CHECK-LABEL: fn borrowed(
// CHECK: bb0: {
// CHECK-NEXT: _3 = &_1;
// CHECK-NEXT: _0 = opaque::<&u32>(_3)
// CHECK-NEXT: _0 = opaque::<&T>(_3)
// CHECK: bb1: {
// CHECK-NEXT: _0 = opaque::<u32>(_1)
// CHECK-NEXT: _0 = opaque::<T>(_1)
mir!(
{
let a = x;
Expand Down
16 changes: 8 additions & 8 deletions tests/mir-opt/gvn.borrowed.GVN.panic-abort.diff
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
- // MIR for `borrowed` before GVN
+ // MIR for `borrowed` after GVN

fn borrowed(_1: u32) -> () {
fn borrowed(_1: T) -> () {
let mut _0: ();
let mut _2: u32;
let mut _3: &u32;
let mut _2: T;
let mut _3: &T;

bb0: {
_2 = _1;
_3 = &_1;
_0 = opaque::<&u32>(_3) -> [return: bb1, unwind unreachable];
_0 = opaque::<&T>(_3) -> [return: bb1, unwind unreachable];
}

bb1: {
- _0 = opaque::<u32>(_2) -> [return: bb2, unwind unreachable];
+ _0 = opaque::<u32>(_1) -> [return: bb2, unwind unreachable];
- _0 = opaque::<T>(_2) -> [return: bb2, unwind unreachable];
+ _0 = opaque::<T>(_1) -> [return: bb2, unwind unreachable];
}

bb2: {
- _0 = opaque::<u32>((*_3)) -> [return: bb3, unwind unreachable];
+ _0 = opaque::<u32>(_1) -> [return: bb3, unwind unreachable];
- _0 = opaque::<T>((*_3)) -> [return: bb3, unwind unreachable];
+ _0 = opaque::<T>(_1) -> [return: bb3, unwind unreachable];
}

bb3: {
Expand Down
16 changes: 8 additions & 8 deletions tests/mir-opt/gvn.borrowed.GVN.panic-unwind.diff
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
- // MIR for `borrowed` before GVN
+ // MIR for `borrowed` after GVN

fn borrowed(_1: u32) -> () {
fn borrowed(_1: T) -> () {
let mut _0: ();
let mut _2: u32;
let mut _3: &u32;
let mut _2: T;
let mut _3: &T;

bb0: {
_2 = _1;
_3 = &_1;
_0 = opaque::<&u32>(_3) -> [return: bb1, unwind continue];
_0 = opaque::<&T>(_3) -> [return: bb1, unwind continue];
}

bb1: {
- _0 = opaque::<u32>(_2) -> [return: bb2, unwind continue];
+ _0 = opaque::<u32>(_1) -> [return: bb2, unwind continue];
- _0 = opaque::<T>(_2) -> [return: bb2, unwind continue];
+ _0 = opaque::<T>(_1) -> [return: bb2, unwind continue];
}

bb2: {
- _0 = opaque::<u32>((*_3)) -> [return: bb3, unwind continue];
+ _0 = opaque::<u32>(_1) -> [return: bb3, unwind continue];
- _0 = opaque::<T>((*_3)) -> [return: bb3, unwind continue];
+ _0 = opaque::<T>(_1) -> [return: bb3, unwind continue];
}

bb3: {
Expand Down
18 changes: 9 additions & 9 deletions tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
let mut _3: fn(u8) -> u8;
let _5: ();
let mut _6: fn(u8) -> u8;
let mut _9: {closure@$DIR/gvn.rs:610:19: 610:21};
let mut _9: {closure@$DIR/gvn.rs:612:19: 612:21};
let _10: ();
let mut _11: fn();
let mut _13: {closure@$DIR/gvn.rs:610:19: 610:21};
let mut _13: {closure@$DIR/gvn.rs:612:19: 612:21};
let _14: ();
let mut _15: fn();
scope 1 {
debug f => _1;
let _4: fn(u8) -> u8;
scope 2 {
debug g => _4;
let _7: {closure@$DIR/gvn.rs:610:19: 610:21};
let _7: {closure@$DIR/gvn.rs:612:19: 612:21};
scope 3 {
debug closure => _7;
let _8: fn();
Expand Down Expand Up @@ -62,16 +62,16 @@
StorageDead(_6);
StorageDead(_5);
- StorageLive(_7);
- _7 = {closure@$DIR/gvn.rs:610:19: 610:21};
- _7 = {closure@$DIR/gvn.rs:612:19: 612:21};
- StorageLive(_8);
+ nop;
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:610:19: 610:21};
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:612:19: 612:21};
+ nop;
StorageLive(_9);
- _9 = _7;
- _8 = move _9 as fn() (PointerCoercion(ClosureFnPointer(Normal)));
+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:610:19: 610:21};
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:610:19: 610:21} as fn() (PointerCoercion(ClosureFnPointer(Normal)));
+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:612:19: 612:21};
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:612:19: 612:21} as fn() (PointerCoercion(ClosureFnPointer(Normal)));
StorageDead(_9);
StorageLive(_10);
StorageLive(_11);
Expand All @@ -88,8 +88,8 @@
StorageLive(_13);
- _13 = _7;
- _12 = move _13 as fn() (PointerCoercion(ClosureFnPointer(Normal)));
+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:610:19: 610:21};
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:610:19: 610:21} as fn() (PointerCoercion(ClosureFnPointer(Normal)));
+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:612:19: 612:21};
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:612:19: 612:21} as fn() (PointerCoercion(ClosureFnPointer(Normal)));
StorageDead(_13);
StorageLive(_14);
StorageLive(_15);
Expand Down
18 changes: 9 additions & 9 deletions tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
let mut _3: fn(u8) -> u8;
let _5: ();
let mut _6: fn(u8) -> u8;
let mut _9: {closure@$DIR/gvn.rs:610:19: 610:21};
let mut _9: {closure@$DIR/gvn.rs:612:19: 612:21};
let _10: ();
let mut _11: fn();
let mut _13: {closure@$DIR/gvn.rs:610:19: 610:21};
let mut _13: {closure@$DIR/gvn.rs:612:19: 612:21};
let _14: ();
let mut _15: fn();
scope 1 {
debug f => _1;
let _4: fn(u8) -> u8;
scope 2 {
debug g => _4;
let _7: {closure@$DIR/gvn.rs:610:19: 610:21};
let _7: {closure@$DIR/gvn.rs:612:19: 612:21};
scope 3 {
debug closure => _7;
let _8: fn();
Expand Down Expand Up @@ -62,16 +62,16 @@
StorageDead(_6);
StorageDead(_5);
- StorageLive(_7);
- _7 = {closure@$DIR/gvn.rs:610:19: 610:21};
- _7 = {closure@$DIR/gvn.rs:612:19: 612:21};
- StorageLive(_8);
+ nop;
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:610:19: 610:21};
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:612:19: 612:21};
+ nop;
StorageLive(_9);
- _9 = _7;
- _8 = move _9 as fn() (PointerCoercion(ClosureFnPointer(Normal)));
+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:610:19: 610:21};
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:610:19: 610:21} as fn() (PointerCoercion(ClosureFnPointer(Normal)));
+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:612:19: 612:21};
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:612:19: 612:21} as fn() (PointerCoercion(ClosureFnPointer(Normal)));
StorageDead(_9);
StorageLive(_10);
StorageLive(_11);
Expand All @@ -88,8 +88,8 @@
StorageLive(_13);
- _13 = _7;
- _12 = move _13 as fn() (PointerCoercion(ClosureFnPointer(Normal)));
+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:610:19: 610:21};
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:610:19: 610:21} as fn() (PointerCoercion(ClosureFnPointer(Normal)));
+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:612:19: 612:21};
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:612:19: 612:21} as fn() (PointerCoercion(ClosureFnPointer(Normal)));
StorageDead(_13);
StorageLive(_14);
StorageLive(_15);
Expand Down
10 changes: 6 additions & 4 deletions tests/mir-opt/gvn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
#![feature(rustc_attrs)]
#![feature(custom_mir)]
#![feature(core_intrinsics)]
#![feature(freeze)]
#![allow(unconditional_panic)]

use std::intrinsics::mir::*;
use std::marker::Freeze;
use std::mem::transmute;

struct S<T>(T);
Expand Down Expand Up @@ -721,16 +723,16 @@ fn wide_ptr_integer() {
}

#[custom_mir(dialect = "analysis", phase = "post-cleanup")]
fn borrowed(x: u32) {
fn borrowed<T: Copy + Freeze>(x: T) {
// CHECK-LABEL: fn borrowed(
// CHECK: bb0: {
// CHECK-NEXT: _2 = _1;
// CHECK-NEXT: _3 = &_1;
// CHECK-NEXT: _0 = opaque::<&u32>(_3)
// CHECK-NEXT: _0 = opaque::<&T>(_3)
// CHECK: bb1: {
// CHECK-NEXT: _0 = opaque::<u32>(_1)
// CHECK-NEXT: _0 = opaque::<T>(_1)
// CHECK: bb2: {
// CHECK-NEXT: _0 = opaque::<u32>(_1)
// CHECK-NEXT: _0 = opaque::<T>(_1)
mir!(
{
let a = x;
Expand Down

0 comments on commit 8ce8fbf

Please sign in to comment.