diff options
| author | bors <bors@rust-lang.org> | 2024-07-26 13:13:04 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-07-26 13:13:04 +0000 |
| commit | 2d5a628a1de1d38318909a710ef37da6251e362e (patch) | |
| tree | 6794a20dc0cff21155b593b8d3733f7a202004a7 /tests/codegen | |
| parent | 355efacf0d430331c962a38af39049b76bb6266b (diff) | |
| parent | a7d57aa7c8f42dda6d33e0ac349cf834eaf041b8 (diff) | |
| download | rust-2d5a628a1de1d38318909a710ef37da6251e362e.tar.gz rust-2d5a628a1de1d38318909a710ef37da6251e362e.zip | |
Auto merge of #128165 - saethlin:optimize-clone-shims, r=compiler-errors
Let InstCombine remove Clone shims inside Clone shims The Clone shims that we generate tend to recurse into other Clone shims, which gets very silly very quickly. Here's our current state: https://godbolt.org/z/E69YeY8eq So I've added InstSimplify to the shims optimization passes, and improved `is_trivially_pure_clone_copy` so that it can delete those calls inside the shim. This makes the shim way smaller because most of its size is the required ceremony for unwinding. This change also completely breaks the UI test added for https://github.com/rust-lang/rust/issues/104870. With this PR, that program ICEs in MIR type checking because `is_trivially_pure_clone_copy` and the trait solver disagree on whether `*mut u8` is `Copy`. And adding the requisite `Copy` impl to make them agree makes the test not generate any diagnostics. Considering that I spent most of my time on this PR fixing `#![no_core]` tests, I would prefer to just delete this one. The maintenance burden of `#![no_core]` is uniquely high because when they break they tend to break in very confusing ways. try-job: x86_64-mingw
Diffstat (limited to 'tests/codegen')
| -rw-r--r-- | tests/codegen/avr/avr-func-addrspace.rs | 1 | ||||
| -rw-r--r-- | tests/codegen/clone-shims.rs | 15 | ||||
| -rw-r--r-- | tests/codegen/emcripten-catch-unwind.rs | 2 | ||||
| -rw-r--r-- | tests/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs | 1 | ||||
| -rw-r--r-- | tests/codegen/sanitizer/kcfi/emit-type-metadata-trait-objects.rs | 1 |
5 files changed, 20 insertions, 0 deletions
diff --git a/tests/codegen/avr/avr-func-addrspace.rs b/tests/codegen/avr/avr-func-addrspace.rs index 70834707564..7f9a7e6e811 100644 --- a/tests/codegen/avr/avr-func-addrspace.rs +++ b/tests/codegen/avr/avr-func-addrspace.rs @@ -17,6 +17,7 @@ pub trait Sized {} #[lang = "copy"] pub trait Copy {} +impl<T: ?Sized> Copy for *const T {} #[lang = "receiver"] pub trait Receiver {} #[lang = "tuple_trait"] diff --git a/tests/codegen/clone-shims.rs b/tests/codegen/clone-shims.rs new file mode 100644 index 00000000000..06c959f9ee7 --- /dev/null +++ b/tests/codegen/clone-shims.rs @@ -0,0 +1,15 @@ +// Clone shims for aggregates are generated by just calling the Clone shims for all their members. +// Those calls generate a lot of unnecessary IR if the members are Copy. This test ensures that we +// optimize away those inner calls without needing to inline them. + +//@ compile-flags: -Cno-prepopulate-passes -Csymbol-mangling-version=v0 -Zinline-mir=no +#![crate_type = "lib"] + +pub type Test = (i32, i32, *const i32); +pub static TEST: fn(&Test) -> Test = <Test as core::clone::Clone>::clone; + +// CHECK-NOT: call <i32 as core::clone::Clone>::clone +// CHECK-NOT: call <*const i32 as core::clone::Clone>::clone +// CHECK: ; <(i32, i32, *const i32) as core::clone::Clone>::clone +// CHECK-NOT: call <i32 as core::clone::Clone>::clone +// CHECK-NOT: call <*const i32 as core::clone::Clone>::clone diff --git a/tests/codegen/emcripten-catch-unwind.rs b/tests/codegen/emcripten-catch-unwind.rs index 6cda8c6799f..35444db9558 100644 --- a/tests/codegen/emcripten-catch-unwind.rs +++ b/tests/codegen/emcripten-catch-unwind.rs @@ -16,6 +16,8 @@ trait Freeze {} #[lang = "copy"] trait Copy {} +impl<T> Copy for *mut T {} + #[rustc_intrinsic] fn size_of<T>() -> usize { loop {} diff --git a/tests/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs b/tests/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs index ed0af90aaaf..520192b5d59 100644 --- a/tests/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs +++ b/tests/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs @@ -18,6 +18,7 @@ impl Copy for i64 {} impl Copy for u64 {} impl Copy for f32 {} impl Copy for f64 {} +impl<T> Copy for *mut T {} // CHECK: define void @f_void() #[no_mangle] diff --git a/tests/codegen/sanitizer/kcfi/emit-type-metadata-trait-objects.rs b/tests/codegen/sanitizer/kcfi/emit-type-metadata-trait-objects.rs index fc4d570dc2e..c1967e55e75 100644 --- a/tests/codegen/sanitizer/kcfi/emit-type-metadata-trait-objects.rs +++ b/tests/codegen/sanitizer/kcfi/emit-type-metadata-trait-objects.rs @@ -15,6 +15,7 @@ trait Sized {} #[lang = "copy"] trait Copy {} +impl<T: ?Sized> Copy for &T {} #[lang = "receiver"] trait Receiver {} #[lang = "dispatch_from_dyn"] |
