From 73db28757b9a0da3c0e0837d995e28cc45ddca7c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 7 Apr 2024 18:33:18 +0000 Subject: [PATCH] Use newly exposed Freeze trait. --- ...ed_local.borrowed.CopyProp.panic-abort.diff | 12 ++++++------ ...d_local.borrowed.CopyProp.panic-unwind.diff | 12 ++++++------ tests/mir-opt/copy-prop/borrowed_local.rs | 10 ++++++---- .../mir-opt/gvn.borrowed.GVN.panic-abort.diff | 16 ++++++++-------- .../mir-opt/gvn.borrowed.GVN.panic-unwind.diff | 16 ++++++++-------- .../gvn.fn_pointers.GVN.panic-abort.diff | 18 +++++++++--------- .../gvn.fn_pointers.GVN.panic-unwind.diff | 18 +++++++++--------- tests/mir-opt/gvn.rs | 10 ++++++---- 8 files changed, 58 insertions(+), 54 deletions(-) diff --git a/tests/mir-opt/copy-prop/borrowed_local.borrowed.CopyProp.panic-abort.diff b/tests/mir-opt/copy-prop/borrowed_local.borrowed.CopyProp.panic-abort.diff index 88c3eda50e4..897592a0e2f 100644 --- a/tests/mir-opt/copy-prop/borrowed_local.borrowed.CopyProp.panic-abort.diff +++ b/tests/mir-opt/copy-prop/borrowed_local.borrowed.CopyProp.panic-abort.diff @@ -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::(_2) -> [return: bb2, unwind unreachable]; -+ _0 = opaque::(_1) -> [return: bb2, unwind unreachable]; +- _0 = opaque::(_2) -> [return: bb2, unwind unreachable]; ++ _0 = opaque::(_1) -> [return: bb2, unwind unreachable]; } bb2: { diff --git a/tests/mir-opt/copy-prop/borrowed_local.borrowed.CopyProp.panic-unwind.diff b/tests/mir-opt/copy-prop/borrowed_local.borrowed.CopyProp.panic-unwind.diff index 8667fcb7594..33c05af91a1 100644 --- a/tests/mir-opt/copy-prop/borrowed_local.borrowed.CopyProp.panic-unwind.diff +++ b/tests/mir-opt/copy-prop/borrowed_local.borrowed.CopyProp.panic-unwind.diff @@ -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::(_2) -> [return: bb2, unwind continue]; -+ _0 = opaque::(_1) -> [return: bb2, unwind continue]; +- _0 = opaque::(_2) -> [return: bb2, unwind continue]; ++ _0 = opaque::(_1) -> [return: bb2, unwind continue]; } bb2: { diff --git a/tests/mir-opt/copy-prop/borrowed_local.rs b/tests/mir-opt/copy-prop/borrowed_local.rs index 13b93327f60..9755eb50a4b 100644 --- a/tests/mir-opt/copy-prop/borrowed_local.rs +++ b/tests/mir-opt/copy-prop/borrowed_local.rs @@ -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(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::(_1) + // CHECK-NEXT: _0 = opaque::(_1) mir!( { let a = x; diff --git a/tests/mir-opt/gvn.borrowed.GVN.panic-abort.diff b/tests/mir-opt/gvn.borrowed.GVN.panic-abort.diff index e0e3136a498..9520bd382ee 100644 --- a/tests/mir-opt/gvn.borrowed.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.borrowed.GVN.panic-abort.diff @@ -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::(_2) -> [return: bb2, unwind unreachable]; -+ _0 = opaque::(_1) -> [return: bb2, unwind unreachable]; +- _0 = opaque::(_2) -> [return: bb2, unwind unreachable]; ++ _0 = opaque::(_1) -> [return: bb2, unwind unreachable]; } bb2: { -- _0 = opaque::((*_3)) -> [return: bb3, unwind unreachable]; -+ _0 = opaque::(_1) -> [return: bb3, unwind unreachable]; +- _0 = opaque::((*_3)) -> [return: bb3, unwind unreachable]; ++ _0 = opaque::(_1) -> [return: bb3, unwind unreachable]; } bb3: { diff --git a/tests/mir-opt/gvn.borrowed.GVN.panic-unwind.diff b/tests/mir-opt/gvn.borrowed.GVN.panic-unwind.diff index e60e1b22c9a..4f5d76d5644 100644 --- a/tests/mir-opt/gvn.borrowed.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.borrowed.GVN.panic-unwind.diff @@ -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::(_2) -> [return: bb2, unwind continue]; -+ _0 = opaque::(_1) -> [return: bb2, unwind continue]; +- _0 = opaque::(_2) -> [return: bb2, unwind continue]; ++ _0 = opaque::(_1) -> [return: bb2, unwind continue]; } bb2: { -- _0 = opaque::((*_3)) -> [return: bb3, unwind continue]; -+ _0 = opaque::(_1) -> [return: bb3, unwind continue]; +- _0 = opaque::((*_3)) -> [return: bb3, unwind continue]; ++ _0 = opaque::(_1) -> [return: bb3, unwind continue]; } bb3: { diff --git a/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff b/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff index 02bf95840da..68cb4d55e7b 100644 --- a/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff @@ -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); diff --git a/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff b/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff index c5dcc8a8ec9..fa184348b3b 100644 --- a/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff @@ -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); diff --git a/tests/mir-opt/gvn.rs b/tests/mir-opt/gvn.rs index 8c2d4db642d..d422e9339cb 100644 --- a/tests/mir-opt/gvn.rs +++ b/tests/mir-opt/gvn.rs @@ -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); @@ -721,16 +723,16 @@ fn wide_ptr_integer() { } #[custom_mir(dialect = "analysis", phase = "post-cleanup")] -fn borrowed(x: u32) { +fn borrowed(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::(_1) + // CHECK-NEXT: _0 = opaque::(_1) // CHECK: bb2: { - // CHECK-NEXT: _0 = opaque::(_1) + // CHECK-NEXT: _0 = opaque::(_1) mir!( { let a = x;