-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Implement push_mut
#135975
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
base: master
Are you sure you want to change the base?
Implement push_mut
#135975
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ibraheemdev (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
Sorry if I did this wrong, it's my first time! |
This comment has been minimized.
This comment has been minimized.
A single trailing whitespace. Oops. |
This comment has been minimized.
This comment has been minimized.
I'm not sure we should be touching |
Alright, I'll do that soon. |
I finally got around to duplicating the implementation. College has been eating my time like a child with Halloween candy, sorry. |
@rustbot review |
library/alloc/src/vec/mod.rs
Outdated
/// | ||
/// let mut vec = vec![]; | ||
/// // Due to current borrow checker limitations (see -Zpolonius), this is the only way to spell this right now. | ||
/// let last = if let Some(v) = vec.last_mut() { v } else { vec.push_mut(0) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the point of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should probably be a better example, yeah. Will update soon!
@balt-dev |
I'm sorry, college has been quite a time sink for me and I haven't had the time to follow up as of recent - I will when I can, promise! |
It's been a rough few months. ._. |
This comment has been minimized.
This comment has been minimized.
hm. |
I think I messed up my fork so bad I'll have to reset it and put my code in from scratch in order to get rid of the merge commit. At least it's copy/pasteable? |
Now mind you, that's a MIR difference, so I'm not sure if it should be ignored or updated or what. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
(cherry picked from commit b48ad8c)
Agh, is there not a way to change the branch you're pushing from? |
Ah, yeah, those should be fine to update. |
God this commit history is a trainwreck. I am so sorry. |
We request squashing before merge for a reason :) feel free to do that at any time too if it keeps things more organized for you. |
This comment has been minimized.
This comment has been minimized.
I'd love to, but for some reason...
curl seems to hate me right now. Will try again later. |
Figured it out - turns out my /tmp was full. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've went ahead and done this.
Let me know if I should revert this change.
This comment has been minimized.
This comment has been minimized.
Thank goodness for that test :P |
Just did some assembly inspection, and got some interesting results: Rust and assembly code blocks#![crate_type = "lib"]
#![feature(push_mut)]
#[inline(never)]
pub fn push_and_get(vec: &mut Vec<i32>, value: i32) -> &mut i32 {
vec.push(value);
vec.last_mut().unwrap()
}
#[inline(never)]
pub fn push_and_unsafe_get(vec: &mut Vec<i32>, value: i32) -> &mut i32 {
vec.push(value);
unsafe { vec.last_mut().unwrap_unchecked() }
}
#[inline(never)]
pub fn push_mut(vec: &mut Vec<i32>, value: i32) -> &mut i32 {
vec.push_mut(value)
} sample::push_and_get:
.cfi_startproc
push r15
.cfi_def_cfa_offset 16
push r14
.cfi_def_cfa_offset 24
push rbx
.cfi_def_cfa_offset 32
.cfi_offset rbx, -32
.cfi_offset r14, -24
.cfi_offset r15, -16
mov ebx, esi
mov r15, qword ptr [rdi + 16]
cmp r15, qword ptr [rdi]
jne .LBB2_2
lea rsi, [rip + .Lanon.b379c6d255dd21da763072d2c3ee59ab.1]
mov r14, rdi
call qword ptr [rip + alloc::raw_vec::RawVec<T,A>::grow_one@GOTPCREL]
mov rax, qword ptr [r14 + 8]
mov dword ptr [rax + 4*r15], ebx
inc r15
mov qword ptr [r14 + 16], r15
jmp .LBB2_3
.LBB2_2:
mov rax, qword ptr [rdi + 8]
mov dword ptr [rax + 4*r15], ebx
inc r15
mov qword ptr [rdi + 16], r15
je .LBB2_4
.LBB2_3:
lea rax, [rax + 4*r15]
add rax, -4
pop rbx
.cfi_def_cfa_offset 24
pop r14
.cfi_def_cfa_offset 16
pop r15
.cfi_def_cfa_offset 8
ret
.LBB2_4:
.cfi_def_cfa_offset 32
lea rdi, [rip + .Lanon.b379c6d255dd21da763072d2c3ee59ab.2]
call qword ptr [rip + core::option::unwrap_failed@GOTPCREL]
sample::push_and_unsafe_get:
.cfi_startproc
push rbp
.cfi_def_cfa_offset 16
push r14
.cfi_def_cfa_offset 24
push rbx
.cfi_def_cfa_offset 32
.cfi_offset rbx, -32
.cfi_offset r14, -24
.cfi_offset rbp, -16
mov ebp, esi
mov rbx, rdi
mov r14, qword ptr [rdi + 16]
cmp r14, qword ptr [rdi]
jne .LBB2_2
lea rsi, [rip + .Lanon.d8d47fb7bb295c1cef687eae3796c8a4.1]
mov rdi, rbx
call qword ptr [rip + alloc::raw_vec::RawVec<T,A>::grow_one@GOTPCREL]
.LBB2_2:
mov rax, qword ptr [rbx + 8]
mov dword ptr [rax + 4*r14], ebp
lea rcx, [r14 + 1]
mov qword ptr [rbx + 16], rcx
lea rax, [rax + 4*r14]
pop rbx
.cfi_def_cfa_offset 24
pop r14
.cfi_def_cfa_offset 16
pop rbp
.cfi_def_cfa_offset 8
ret
sample::push_mut:
.cfi_startproc
push rbp
.cfi_def_cfa_offset 16
push r14
.cfi_def_cfa_offset 24
push rbx
.cfi_def_cfa_offset 32
.cfi_offset rbx, -32
.cfi_offset r14, -24
.cfi_offset rbp, -16
mov ebp, esi
mov rbx, rdi
mov r14, qword ptr [rdi + 16]
cmp r14, qword ptr [rdi]
jne .LBB3_2
lea rsi, [rip + .Lanon.b379c6d255dd21da763072d2c3ee59ab.3]
mov rdi, rbx
call qword ptr [rip + alloc::raw_vec::RawVec<T,A>::grow_one@GOTPCREL]
.LBB3_2:
mov rcx, qword ptr [rbx + 8]
lea rax, [rcx + 4*r14]
mov dword ptr [rcx + 4*r14], ebp
inc r14
mov qword ptr [rbx + 16], r14
pop rbx
.cfi_def_cfa_offset 24
pop r14
.cfi_def_cfa_offset 16
pop rbp
.cfi_def_cfa_offset 8
ret Doing a |
@rustbot review |
library/alloc/src/vec/mod.rs
Outdated
fn assert_failed(index: usize, len: usize) -> ! { | ||
panic!("insertion index (is {index}) should be <= len (is {len})"); | ||
} | ||
assert!(self.insert_mut(index, element).is_some(), "index out of bounds"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be losing some optimization here. I'm not well-versed enough to know what the hell some of these attributes do.
The job Click to see the possible cause of the failure (guessed by this bot)
|
This is why I shouldn't program after 9 PM. Will fix when I wake up
tomorrow.
|
Implementation of #135974.