rust/library
bors b06258cde4 Auto merge of #118228 - Mark-Simulacrum:alloc-opt, r=scottmcm
Indicate that multiplication in Layout::array cannot overflow

Since https://github.com/rust-lang/rust/pull/113113, we have added a check that skips calling into the allocator at all if `capacity == 0`. The global, default allocator will not actually try to allocate though; it returns a dangling pointer explicitly. However, these two checks are not merged/deduplicated by LLVM and so we're comparing to zero twice whenever vectors are allocated/grown. Probably cheap, but also potentially expensive in code size and seems like an unfortunate miss.

This removes that extra check by telling LLVM that the multiplication as part of Layout::array can't overflow, turning the original non-zero value into a zero value afterwards. In my checks locally this successfully drops the duplicate comparisons.

See https://rust.godbolt.org/z/b6nPP9dcK for a code example.

```rust
pub fn foo(elements: usize) -> Vec<u32> {
    Vec::with_capacity(elements)
}
```

r? `@scottmcm` since you touched this in a32305a80f - curious if you have thoughts on doing this / can confirm my model of this being correct.
2023-11-24 11:19:34 +00:00
..
alloc docs(GH-118094): make docs a bit more explicit 2023-11-20 18:35:04 +03:00
backtrace@6145fe6bac Update backtrace submodule 2023-11-21 16:33:42 +01:00
core Auto merge of #118228 - Mark-Simulacrum:alloc-opt, r=scottmcm 2023-11-24 11:19:34 +00:00
panic_abort Rebase to master 2023-09-22 17:23:33 +05:30
panic_unwind Use pointers instead of usize addresses for landing pads 2023-10-10 09:59:39 +02:00
portable-simd use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
proc_macro Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
profiler_builtins Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
rtstartup
rustc-std-workspace-alloc
rustc-std-workspace-core
rustc-std-workspace-std
std Rollup merge of #118060 - ChrisDenton:abs-device-path, r=thomcc 2023-11-24 08:23:53 +01:00
stdarch@f4528dd6e8 Bump stdarch submodule 2023-10-12 11:11:29 +02:00
sysroot Expose compiler-builtins-weak-intrinsics feature for -Zbuild-std 2023-06-23 11:15:34 +01:00
test Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
unwind Remove obsolete support for linking unwinder on Android 2023-11-02 18:06:35 -07:00