Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop re-implementing slice iterators in vec::IntoIter #124421

Closed
wants to merge 8 commits into from
Prev Previous commit
Next Next commit
Add codegen tests for vec::IntoIter::next_chunk
scottmcm committed Apr 27, 2024
commit 0fe05cce1bf4177a2f02f2c45bc8a4213b911450
62 changes: 61 additions & 1 deletion tests/codegen/vec-iter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//@ compile-flags: -O
//@ min-llvm-version: 18 (which added `dead_on_unwind`)
#![crate_type = "lib"]
#![feature(exact_size_is_empty)]
#![feature(iter_advance_by)]
#![feature(iter_next_chunk)]

use std::vec;
use std::{array, vec};

// CHECK-LABEL: @vec_iter_len_nonnull
#[no_mangle]
@@ -56,3 +59,60 @@ pub fn vec_iter_next_back_nonnull(it: &mut vec::IntoIter<u8>) -> Option<u8> {
// CHECK: ret
it.next_back()
}

// CHECK-LABEL: @vec_iter_next_transfers_ownership
#[no_mangle]
pub fn vec_iter_next_transfers_ownership(it: &mut vec::IntoIter<Box<i32>>) -> Option<Box<i32>> {
// CHECK-NOT: __rust_dealloc
it.next()
}

// CHECK-LABEL: @vec_iter_advance_drops_item
#[no_mangle]
pub fn vec_iter_advance_drops_item(it: &mut vec::IntoIter<Box<i32>>) {
// CHECK-NOT: __rust_dealloc
// CHECK: call void @__rust_dealloc
// CHECK-SAME: noundef 4
// CHECK-SAME: noundef 4
// CHECK-NOT: __rust_dealloc
_ = it.advance_by(1);
}

// CHECK-LABEL: @vec_iter_next_chunk_short
// CHECK-SAME: ptr{{.+}}%[[RET:.+]],
#[no_mangle]
pub fn vec_iter_next_chunk_short(
it: &mut vec::IntoIter<u8>,
) -> Result<[u8; 4], array::IntoIter<u8, 4>> {
// CHECK-NOT: alloca
// CHECK: %[[ACTUAL_LEN:.+]] = sub nuw

// CHECK: %[[OUT1:.+]] = getelementptr inbounds i8, ptr %[[RET]]
// CHECK: call void @llvm.memcpy{{.+}}(ptr{{.+}}%[[OUT1]],{{.+}} %[[ACTUAL_LEN]], i1 false)
// CHECK: br

// CHECK: %[[FULL:.+]] = load i32,
// CHECK: %[[OUT2:.+]] = getelementptr inbounds i8, ptr %[[RET]]
// CHECK: store i32 %[[FULL]], ptr %[[OUT2]]
// CHECK: br
it.next_chunk::<4>()
}

// CHECK-LABEL: @vec_iter_next_chunk_long
// CHECK-SAME: ptr{{.+}}%[[RET:.+]],
#[no_mangle]
pub fn vec_iter_next_chunk_long(
it: &mut vec::IntoIter<u8>,
) -> Result<[u8; 123], array::IntoIter<u8, 123>> {
// CHECK-NOT: alloca
// CHECK: %[[ACTUAL_LEN:.+]] = sub nuw

// CHECK: %[[OUT1:.+]] = getelementptr inbounds i8, ptr %[[RET]]
// CHECK: call void @llvm.memcpy{{.+}}(ptr{{.+}}%[[OUT1]],{{.+}} %[[ACTUAL_LEN]], i1 false)
// CHECK: br

// CHECK: %[[OUT2:.+]] = getelementptr inbounds i8, ptr %[[RET]]
// CHECK: call void @llvm.memcpy{{.+}}(ptr{{.+}}%[[OUT2]],{{.+}} 123, i1 false)
// CHECK: br
it.next_chunk::<123>()
}