From 1f35769f994ebd00d5a93125f5e1f7856a90d1e5 Mon Sep 17 00:00:00 2001 From: Ryan Mehri Date: Sun, 22 Oct 2023 09:27:43 -0700 Subject: [PATCH] address review comments --- tests/mir-opt/inline/asm_unwind.rs | 3 + .../inline/caller_with_trivial_bound.rs | 3 + tests/mir-opt/inline/cycle.rs | 2 + .../inline/dont_ice_on_generic_rust_call.rs | 2 +- tests/mir-opt/inline/dyn_trait.rs | 4 +- tests/mir-opt/inline/exponential_runtime.rs | 1 + tests/mir-opt/inline/inline_box_fn.rs | 2 +- .../inline/inline_retag.bar.Inline.after.mir | 59 ----------------- .../inline/inline_retag.bar.Inline.diff | 65 +++++++++++++++++++ tests/mir-opt/inline/inline_retag.rs | 11 +++- tests/mir-opt/inline/inline_trait_method.rs | 3 +- ...ine_scopes_parenting.main.Inline.after.mir | 6 +- .../issue_76997_inline_scopes_parenting.rs | 9 ++- 13 files changed, 100 insertions(+), 70 deletions(-) delete mode 100644 tests/mir-opt/inline/inline_retag.bar.Inline.after.mir create mode 100644 tests/mir-opt/inline/inline_retag.bar.Inline.diff diff --git a/tests/mir-opt/inline/asm_unwind.rs b/tests/mir-opt/inline/asm_unwind.rs index 596a4592f25ff..0ae20e5221110 100644 --- a/tests/mir-opt/inline/asm_unwind.rs +++ b/tests/mir-opt/inline/asm_unwind.rs @@ -2,6 +2,7 @@ // // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // needs-asm-support +// needs-unwind // compile-flags: -Zinline-mir-hint-threshold=1000 #![feature(asm_unwind)] @@ -21,5 +22,7 @@ fn foo() { pub fn main() { // CHECK-LABEL: fn main( // CHECK: (inlined foo) + // CHECK: asm!("", options(MAY_UNWIND)) -> [return: {{bb.*}}, unwind: [[unwind:bb.*]]]; + // CHECK: [[unwind]] (cleanup) foo(); } diff --git a/tests/mir-opt/inline/caller_with_trivial_bound.rs b/tests/mir-opt/inline/caller_with_trivial_bound.rs index 722c7f6724efd..40f7f4bbab2f7 100644 --- a/tests/mir-opt/inline/caller_with_trivial_bound.rs +++ b/tests/mir-opt/inline/caller_with_trivial_bound.rs @@ -15,6 +15,9 @@ impl Factory for IntFactory { // EMIT_MIR caller_with_trivial_bound.foo.Inline.diff pub fn foo() where + // Because of this trivial bound, the inliner fails to normalize + // `>::Item`. + // Verify that we do not inline anything, which would cause validation ICEs. IntFactory: Factory, { // CHECK-LABEL: fn foo( diff --git a/tests/mir-opt/inline/cycle.rs b/tests/mir-opt/inline/cycle.rs index 8716b44b3dc02..350724235ba04 100644 --- a/tests/mir-opt/inline/cycle.rs +++ b/tests/mir-opt/inline/cycle.rs @@ -13,6 +13,7 @@ fn f(g: impl Fn()) { #[inline(always)] fn g() { // CHECK-LABEL: fn g( + // CHECK-NOT: inlined // CHECK: (inlined f::) // CHECK-NOT: inlined f(main); @@ -21,6 +22,7 @@ fn g() { // EMIT_MIR cycle.main.Inline.diff fn main() { // CHECK-LABEL: fn main( + // CHECK-NOT: inlined // CHECK: (inlined f::) // CHECK-NOT: inlined f(g); diff --git a/tests/mir-opt/inline/dont_ice_on_generic_rust_call.rs b/tests/mir-opt/inline/dont_ice_on_generic_rust_call.rs index 3307a1408fb56..ce5e1855a716b 100644 --- a/tests/mir-opt/inline/dont_ice_on_generic_rust_call.rs +++ b/tests/mir-opt/inline/dont_ice_on_generic_rust_call.rs @@ -8,6 +8,6 @@ use std::marker::Tuple; // EMIT_MIR dont_ice_on_generic_rust_call.call.Inline.diff pub fn call(mut mock: Box>, input: I) { // CHECK-LABEL: fn call( - // CHECK-NOT: (inlined > as FnMut>::call_mut) + // CHECK-NOT: inlined mock.call_mut(input) } diff --git a/tests/mir-opt/inline/dyn_trait.rs b/tests/mir-opt/inline/dyn_trait.rs index 005cf155fdb93..ecf220a85e6a3 100644 --- a/tests/mir-opt/inline/dyn_trait.rs +++ b/tests/mir-opt/inline/dyn_trait.rs @@ -20,7 +20,7 @@ pub trait Query { #[inline(always)] pub fn mk_cycle(c: &dyn Cache) { // CHECK-LABEL: fn mk_cycle( - // CHECK-NOT: (inlined as Cache>::store_nocache) + // CHECK-NOT: inlined c.store_nocache() } @@ -36,7 +36,7 @@ pub fn try_execute_query(c: &C) { #[inline(always)] pub fn get_query(t: &T) { // CHECK-LABEL: fn get_query( - // CHECK-NOT: (inlined ::cache::) + // CHECK-NOT: inlined let c = Q::cache(t); // CHECK: (inlined try_execute_query::<::C>) // CHECK: (inlined mk_cycle::<::V>) diff --git a/tests/mir-opt/inline/exponential_runtime.rs b/tests/mir-opt/inline/exponential_runtime.rs index 499bec33ffc9b..1199ce4e5588e 100644 --- a/tests/mir-opt/inline/exponential_runtime.rs +++ b/tests/mir-opt/inline/exponential_runtime.rs @@ -85,6 +85,7 @@ impl A for () { // EMIT_MIR exponential_runtime.main.Inline.diff fn main() { // CHECK-LABEL: fn main( + // CHECK-NOT: inlined // CHECK: (inlined <() as G>::call) // CHECK: (inlined <() as F>::call) // CHECK: (inlined <() as E>::call) diff --git a/tests/mir-opt/inline/inline_box_fn.rs b/tests/mir-opt/inline/inline_box_fn.rs index 7686477c291a3..d2da239399235 100644 --- a/tests/mir-opt/inline/inline_box_fn.rs +++ b/tests/mir-opt/inline/inline_box_fn.rs @@ -5,6 +5,6 @@ // EMIT_MIR inline_box_fn.call.Inline.diff fn call(x: Box) { // CHECK-LABEL: fn call( - // CHECK-NOT: (inlined as Fn<(i32,)>>::call) + // CHECK-NOT: inlined x(1); } diff --git a/tests/mir-opt/inline/inline_retag.bar.Inline.after.mir b/tests/mir-opt/inline/inline_retag.bar.Inline.after.mir deleted file mode 100644 index 8c3f3a4589e63..0000000000000 --- a/tests/mir-opt/inline/inline_retag.bar.Inline.after.mir +++ /dev/null @@ -1,59 +0,0 @@ -// MIR for `bar` after Inline - -fn bar() -> bool { - let mut _0: bool; - let _1: for<'a, 'b> fn(&'a i32, &'b i32) -> bool {foo}; - let mut _2: for<'a, 'b> fn(&'a i32, &'b i32) -> bool {foo}; - let mut _3: &i32; - let _4: &i32; - let _5: i32; - let mut _6: &i32; - let _7: &i32; - let _8: i32; - scope 1 { - debug f => _1; - let mut _9: &i32; - let mut _10: &i32; - scope 2 (inlined foo) { - debug x => _3; - debug y => _6; - let mut _11: i32; - let mut _12: i32; - } - } - - bb0: { - StorageLive(_1); - _1 = foo; - StorageLive(_2); - _2 = _1; - StorageLive(_3); - StorageLive(_4); - _10 = const _; - Retag(_10); - _4 = &(*_10); - _3 = &(*_4); - StorageLive(_6); - StorageLive(_7); - _9 = const _; - Retag(_9); - _7 = &(*_9); - _6 = &(*_7); - Retag(_3); - Retag(_6); - StorageLive(_11); - _11 = (*_3); - StorageLive(_12); - _12 = (*_6); - _0 = Eq(move _11, move _12); - StorageDead(_12); - StorageDead(_11); - StorageDead(_6); - StorageDead(_3); - StorageDead(_2); - StorageDead(_1); - StorageDead(_7); - StorageDead(_4); - return; - } -} diff --git a/tests/mir-opt/inline/inline_retag.bar.Inline.diff b/tests/mir-opt/inline/inline_retag.bar.Inline.diff new file mode 100644 index 0000000000000..8f53f6342ec6d --- /dev/null +++ b/tests/mir-opt/inline/inline_retag.bar.Inline.diff @@ -0,0 +1,65 @@ +- // MIR for `bar` before Inline ++ // MIR for `bar` after Inline + + fn bar() -> bool { + let mut _0: bool; + let _1: for<'a, 'b> fn(&'a i32, &'b i32) -> bool {foo}; + let mut _2: for<'a, 'b> fn(&'a i32, &'b i32) -> bool {foo}; + let mut _3: &i32; + let _4: &i32; + let _5: i32; + let mut _6: &i32; + let _7: &i32; + let _8: i32; + scope 1 { + debug f => _1; + let mut _9: &i32; + let mut _10: &i32; ++ scope 2 (inlined foo) { ++ debug x => _3; ++ debug y => _6; ++ let mut _11: i32; ++ let mut _12: i32; ++ } + } + + bb0: { + StorageLive(_1); + _1 = foo; + StorageLive(_2); + _2 = _1; + StorageLive(_3); + StorageLive(_4); + _10 = const _; + Retag(_10); + _4 = &(*_10); + _3 = &(*_4); + StorageLive(_6); + StorageLive(_7); + _9 = const _; + Retag(_9); + _7 = &(*_9); + _6 = &(*_7); +- _0 = move _2(move _3, move _6) -> [return: bb1, unwind continue]; +- } +- +- bb1: { ++ Retag(_3); ++ Retag(_6); ++ StorageLive(_11); ++ _11 = (*_3); ++ StorageLive(_12); ++ _12 = (*_6); ++ _0 = Eq(move _11, move _12); ++ StorageDead(_12); ++ StorageDead(_11); + StorageDead(_6); + StorageDead(_3); + StorageDead(_2); + StorageDead(_1); + StorageDead(_7); + StorageDead(_4); + return; + } + } + diff --git a/tests/mir-opt/inline/inline_retag.rs b/tests/mir-opt/inline/inline_retag.rs index c90c0b819b7ba..b9058905892bf 100644 --- a/tests/mir-opt/inline/inline_retag.rs +++ b/tests/mir-opt/inline/inline_retag.rs @@ -6,10 +6,19 @@ fn main() { println!("{}", bar()); } -// EMIT_MIR inline_retag.bar.Inline.after.mir +// EMIT_MIR inline_retag.bar.Inline.diff fn bar() -> bool { // CHECK-LABEL: fn bar( // CHECK: (inlined foo) + // CHECK: debug x => [[x:_.*]]; + // CHECK: debug y => [[y:_.*]]; + // CHECK: bb0: { + // CHECK: Retag + // CHECK: Retag + // CHECK: Retag([[x]]); + // CHECK: Retag([[y]]); + // CHECK: return; + // CHECK-NEXT: } let f = foo; f(&1, &-1) } diff --git a/tests/mir-opt/inline/inline_trait_method.rs b/tests/mir-opt/inline/inline_trait_method.rs index ea09966a2aa94..b39355637a1c5 100644 --- a/tests/mir-opt/inline/inline_trait_method.rs +++ b/tests/mir-opt/inline/inline_trait_method.rs @@ -1,3 +1,4 @@ +// Verify that we do not inline the default impl in a trait object. // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // compile-flags: -Z span_free_formats @@ -8,7 +9,7 @@ fn main() { // EMIT_MIR inline_trait_method.test.Inline.after.mir fn test(x: &dyn X) -> u32 { // CHECK-LABEL: fn test( - // CHECK-NOT: (inlined ::y) + // CHECK-NOT: inlined x.y() } diff --git a/tests/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir b/tests/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir index ba5eb757cf977..ba4f91b28d536 100644 --- a/tests/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir +++ b/tests/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir @@ -2,8 +2,8 @@ fn main() -> () { let mut _0: (); - let _1: {closure@$DIR/issue_76997_inline_scopes_parenting.rs:10:13: 10:16}; - let mut _2: &{closure@$DIR/issue_76997_inline_scopes_parenting.rs:10:13: 10:16}; + let _1: {closure@$DIR/issue_76997_inline_scopes_parenting.rs:15:13: 15:16}; + let mut _2: &{closure@$DIR/issue_76997_inline_scopes_parenting.rs:15:13: 15:16}; let mut _3: ((),); let mut _4: (); let mut _5: (); @@ -19,7 +19,7 @@ fn main() -> () { bb0: { StorageLive(_1); - _1 = {closure@$DIR/issue_76997_inline_scopes_parenting.rs:10:13: 10:16}; + _1 = {closure@$DIR/issue_76997_inline_scopes_parenting.rs:15:13: 15:16}; StorageLive(_2); _2 = &_1; StorageLive(_3); diff --git a/tests/mir-opt/inline/issue_76997_inline_scopes_parenting.rs b/tests/mir-opt/inline/issue_76997_inline_scopes_parenting.rs index 2a7c931a659ee..2fb363c19044d 100644 --- a/tests/mir-opt/inline/issue_76997_inline_scopes_parenting.rs +++ b/tests/mir-opt/inline/issue_76997_inline_scopes_parenting.rs @@ -3,10 +3,15 @@ // EMIT_MIR issue_76997_inline_scopes_parenting.main.Inline.after.mir fn main() { // CHECK-LABEL: fn main( - // CHECK: scope 2 + // CHECK: scope 1 { + // CHECK-NEXT: debug f + // CHECK-NEXT: scope 2 (inlined main::{closure#0}) { // CHECK-NEXT: debug x - // CHECK-NEXT: scope 3 + // CHECK-NEXT: scope 3 { // CHECK-NEXT: debug y + // CHECK-NEXT: } + // CHECK-NEXT: } + // CHECK-NEXT: } let f = |x| { let y = x; y }; f(()) }