Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
59a3a5d
Clarify atomic bit validity
joshlf Mar 3, 2024
db34b08
Clarify bit validity for AtomicBool
joshlf Mar 3, 2024
00d21c9
Document AtomicPtr bit validity
joshlf Mar 3, 2024
fba87f6
Use "size and alignment" rather than layout
joshlf Mar 3, 2024
c50804c
Update library/core/src/sync/atomic.rs
joshlf Mar 3, 2024
a6e3e02
Update library/core/src/sync/atomic.rs
joshlf Mar 3, 2024
083ee83
Add invariant to VecDeque::pop_* that len < cap if pop successful
Philippe-Cholet Mar 26, 2024
804c047
Load missing type of impl associated constant from trait definition
oli-obk Mar 27, 2024
d0eb9c8
move type inference for missing types on constants into its own method
oli-obk Mar 27, 2024
7786ee3
Remove a call-site to `primary_body_of` as it is only interested in t…
oli-obk Mar 27, 2024
86e750f
Inline `primary_body_of` into its sole call site
oli-obk Mar 27, 2024
0cd9708
Delegation: fix ICE on wrong instantiation
Bryanskiy Mar 26, 2024
3157114
chore: fix some comments
xiaoxiangxianzi Mar 27, 2024
cc4a1f4
Some wording improvement
Vagelis-Prokopiou Mar 27, 2024
336ff42
`num::NonZero::get` can be 1 transmute instead of 3
scottmcm Mar 27, 2024
df4eec8
Let nils know about changes to target docs
Noratrieb Mar 27, 2024
307ebfd
Rollup merge of #121943 - joshlf:patch-11, r=scottmcm
matthiaskrgr Mar 27, 2024
8322a3b
Rollup merge of #123089 - Philippe-Cholet:vecdeque_pop_assume_cap, r=…
matthiaskrgr Mar 27, 2024
8427c80
Rollup merge of #123101 - Bryanskiy:delegation-fixes-2, r=petrochenkov
matthiaskrgr Mar 27, 2024
3a8cacb
Rollup merge of #123130 - oli-obk:missing_type_taint, r=compiler-errors
matthiaskrgr Mar 27, 2024
abe937a
Rollup merge of #123133 - xiaoxiangxianzi:master, r=fmease
matthiaskrgr Mar 27, 2024
fced740
Rollup merge of #123136 - Vagelis-Prokopiou:fix/docs, r=ChrisDenton
matthiaskrgr Mar 27, 2024
f53f843
Rollup merge of #123139 - scottmcm:simpler-nonzero-get, r=jhpratt
matthiaskrgr Mar 27, 2024
98fa10e
Rollup merge of #123142 - Nilstrieb:nils-knows-whats-happening, r=com…
matthiaskrgr Mar 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add invariant to VecDeque::pop_* that len < cap if pop successful
Similar to #114370 for VecDeque instead of Vec. It now uses `core::hint::assert_unchecked`.
  • Loading branch information
Philippe-Cholet committed Mar 26, 2024
commit 083ee8369bb76bb130f6e60e0d0c939ee929c345
10 changes: 8 additions & 2 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,10 @@ impl<T, A: Allocator> VecDeque<T, A> {
let old_head = self.head;
self.head = self.to_physical_idx(1);
self.len -= 1;
Some(unsafe { self.buffer_read(old_head) })
unsafe {
core::hint::assert_unchecked(self.len < self.capacity());
Some(self.buffer_read(old_head))
}
}
}

Expand All @@ -1638,7 +1641,10 @@ impl<T, A: Allocator> VecDeque<T, A> {
None
} else {
self.len -= 1;
Some(unsafe { self.buffer_read(self.to_physical_idx(self.len)) })
unsafe {
core::hint::assert_unchecked(self.len < self.capacity());
Some(self.buffer_read(self.to_physical_idx(self.len)))
}
}
}

Expand Down
75 changes: 75 additions & 0 deletions tests/codegen/vecdeque_pop_push.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//@ compile-flags: -O

#![crate_type = "lib"]

use std::collections::VecDeque;

#[no_mangle]
// CHECK-LABEL: @noop_back(
pub fn noop_back(v: &mut VecDeque<u8>) {
// CHECK-NOT: reserve_for_push
// CHECK-NOT: call
// CHECK: tail call void @llvm.assume
// CHECK-NOT: reserve_for_push
// CHECK-NOT: call
// CHECK: ret
if let Some(x) = v.pop_back() {
v.push_back(x);
}
}

#[no_mangle]
// CHECK-LABEL: @noop_front(
pub fn noop_front(v: &mut VecDeque<u8>) {
// CHECK-NOT: reserve_for_push
// CHECK-NOT: call
// CHECK: tail call void @llvm.assume
// CHECK-NOT: reserve_for_push
// CHECK-NOT: call
// CHECK: ret
if let Some(x) = v.pop_front() {
v.push_front(x);
}
}

#[no_mangle]
// CHECK-LABEL: @move_byte_front_to_back(
pub fn move_byte_front_to_back(v: &mut VecDeque<u8>) {
// CHECK-NOT: reserve_for_push
// CHECK-NOT: call
// CHECK: tail call void @llvm.assume
// CHECK-NOT: reserve_for_push
// CHECK-NOT: call
// CHECK: ret
if let Some(x) = v.pop_front() {
v.push_back(x);
}
}

#[no_mangle]
// CHECK-LABEL: @move_byte_back_to_front(
pub fn move_byte_back_to_front(v: &mut VecDeque<u8>) {
// CHECK-NOT: reserve_for_push
// CHECK-NOT: call
// CHECK: tail call void @llvm.assume
// CHECK-NOT: reserve_for_push
// CHECK-NOT: call
// CHECK: ret
if let Some(x) = v.pop_back() {
v.push_front(x);
}
}

#[no_mangle]
// CHECK-LABEL: @push_back_byte(
pub fn push_back_byte(v: &mut VecDeque<u8>) {
// CHECK: call {{.*}}reserve_for_push
v.push_back(3);
}

#[no_mangle]
// CHECK-LABEL: @push_front_byte(
pub fn push_front_byte(v: &mut VecDeque<u8>) {
// CHECK: call {{.*}}reserve_for_push
v.push_front(3);
}