Skip to content

Commit 5061e2d

Browse files
committed
Auto merge of rust-lang#86383 - shamatar:slice_len_lowering, r=bjorn3
Add MIR pass to lower call to `core::slice::len` into `Len` operand During some larger experiment with range analysis I've found that code like `let l = slice.len()` produces different MIR then one found in bound checks. This optimization pass replaces terminators that are calls to `core::slice::len` with just a MIR operand and Goto terminator. It uses some heuristics to remove the outer borrow that is made to call `core::slice::len`, but I assume it can be eliminated, just didn't find how. Would like to express my gratitude to `@oli-obk` who helped me a lot on Zullip
2 parents b3e4456 + 0e0188c commit 5061e2d

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

core/src/slice/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ impl<T> [T] {
9696
/// assert_eq!(a.len(), 3);
9797
/// ```
9898
#[doc(alias = "length")]
99+
#[cfg_attr(not(bootstrap), lang = "slice_len_fn")]
99100
#[stable(feature = "rust1", since = "1.0.0")]
100101
#[rustc_const_stable(feature = "const_slice_len", since = "1.39.0")]
101102
#[inline]

std/src/thread/local/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ fn join_orders_after_tls_destructors() {
297297
.unwrap();
298298

299299
loop {
300-
match SYNC_STATE.compare_exchange_weak(
300+
match SYNC_STATE.compare_exchange(
301301
THREAD1_WAITING,
302302
MAIN_THREAD_RENDEZVOUS,
303303
Ordering::SeqCst,

0 commit comments

Comments
 (0)