Use newly exposed Freeze trait.

This commit is contained in:
Camille GILLOT 2024-04-07 18:33:18 +00:00
parent e12ef7984b
commit 73db28757b
8 changed files with 58 additions and 54 deletions

View File

@ -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: {

View File

@ -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: {

View File

@ -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 }
@ -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;

View File

@ -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: {

View File

@ -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: {

View File

@ -8,10 +8,10 @@
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 {
@ -19,7 +19,7 @@
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();
@ -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);
@ -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);

View File

@ -8,10 +8,10 @@
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 {
@ -19,7 +19,7 @@
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();
@ -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);
@ -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);

View File

@ -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);
@ -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;